Rename pytest_collect_file fspath parameter to file_path
This commit is contained in:
parent
bd2de2b442
commit
714d7f430a
|
@ -11,7 +11,7 @@ from _pytest.nodes import _check_path
|
|||
# hookname: (Path, LEGACY_PATH)
|
||||
imply_paths_hooks = {
|
||||
"pytest_ignore_collect": ("collection_path", "path"),
|
||||
"pytest_collect_file": ("fspath", "path"),
|
||||
"pytest_collect_file": ("file_path", "path"),
|
||||
"pytest_pycollect_makemodule": ("fspath", "path"),
|
||||
"pytest_report_header": ("startpath", "startdir"),
|
||||
"pytest_report_collectionfinish": ("startpath", "startdir"),
|
||||
|
|
|
@ -120,18 +120,18 @@ def pytest_unconfigure() -> None:
|
|||
|
||||
|
||||
def pytest_collect_file(
|
||||
fspath: Path,
|
||||
file_path: Path,
|
||||
parent: Collector,
|
||||
) -> Optional[Union["DoctestModule", "DoctestTextfile"]]:
|
||||
config = parent.config
|
||||
if fspath.suffix == ".py":
|
||||
if file_path.suffix == ".py":
|
||||
if config.option.doctestmodules and not any(
|
||||
(_is_setup_py(fspath), _is_main_py(fspath))
|
||||
(_is_setup_py(file_path), _is_main_py(file_path))
|
||||
):
|
||||
mod: DoctestModule = DoctestModule.from_parent(parent, path=fspath)
|
||||
mod: DoctestModule = DoctestModule.from_parent(parent, path=file_path)
|
||||
return mod
|
||||
elif _is_doctest(config, fspath, parent):
|
||||
txt: DoctestTextfile = DoctestTextfile.from_parent(parent, path=fspath)
|
||||
elif _is_doctest(config, file_path, parent):
|
||||
txt: DoctestTextfile = DoctestTextfile.from_parent(parent, path=file_path)
|
||||
return txt
|
||||
return None
|
||||
|
||||
|
|
|
@ -283,17 +283,17 @@ def pytest_ignore_collect(
|
|||
|
||||
|
||||
def pytest_collect_file(
|
||||
fspath: Path, path: "LEGACY_PATH", parent: "Collector"
|
||||
file_path: Path, path: "LEGACY_PATH", parent: "Collector"
|
||||
) -> "Optional[Collector]":
|
||||
"""Create a Collector for the given path, or None if not relevant.
|
||||
|
||||
The new node needs to have the specified ``parent`` as a parent.
|
||||
|
||||
:param pathlib.Path fspath: The path to analyze.
|
||||
:param pathlib.Path file_path: The path to analyze.
|
||||
:param LEGACY_PATH path: The path to collect (deprecated).
|
||||
|
||||
.. versionchanged:: 7.0.0
|
||||
The ``fspath`` parameter was added as a :class:`pathlib.Path`
|
||||
The ``file_path`` parameter was added as a :class:`pathlib.Path`
|
||||
equivalent of the ``path`` parameter. The ``path`` parameter
|
||||
has been deprecated.
|
||||
"""
|
||||
|
|
|
@ -586,7 +586,7 @@ class Session(nodes.FSCollector):
|
|||
else:
|
||||
duplicate_paths.add(fspath)
|
||||
|
||||
return ihook.pytest_collect_file(fspath=fspath, parent=self) # type: ignore[no-any-return]
|
||||
return ihook.pytest_collect_file(file_path=fspath, parent=self) # type: ignore[no-any-return]
|
||||
|
||||
@overload
|
||||
def perform_collect(
|
||||
|
|
|
@ -195,15 +195,17 @@ def pytest_pyfunc_call(pyfuncitem: "Function") -> Optional[object]:
|
|||
return True
|
||||
|
||||
|
||||
def pytest_collect_file(fspath: Path, parent: nodes.Collector) -> Optional["Module"]:
|
||||
if fspath.suffix == ".py":
|
||||
if not parent.session.isinitpath(fspath):
|
||||
def pytest_collect_file(file_path: Path, parent: nodes.Collector) -> Optional["Module"]:
|
||||
if file_path.suffix == ".py":
|
||||
if not parent.session.isinitpath(file_path):
|
||||
if not path_matches_patterns(
|
||||
fspath, parent.config.getini("python_files") + ["__init__.py"]
|
||||
file_path, parent.config.getini("python_files") + ["__init__.py"]
|
||||
):
|
||||
return None
|
||||
ihook = parent.session.gethookproxy(fspath)
|
||||
module: Module = ihook.pytest_pycollect_makemodule(fspath=fspath, parent=parent)
|
||||
ihook = parent.session.gethookproxy(file_path)
|
||||
module: Module = ihook.pytest_pycollect_makemodule(
|
||||
fspath=file_path, parent=parent
|
||||
)
|
||||
return module
|
||||
return None
|
||||
|
||||
|
@ -705,7 +707,7 @@ class Package(Module):
|
|||
else:
|
||||
duplicate_paths.add(fspath)
|
||||
|
||||
return ihook.pytest_collect_file(fspath=fspath, parent=self) # type: ignore[no-any-return]
|
||||
return ihook.pytest_collect_file(file_path=fspath, parent=self) # type: ignore[no-any-return]
|
||||
|
||||
def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
|
||||
this_path = self.path.parent
|
||||
|
|
|
@ -303,9 +303,9 @@ class TestGeneralUsage:
|
|||
class MyCollector(pytest.File):
|
||||
def collect(self):
|
||||
return [MyItem.from_parent(name="xyz", parent=self)]
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.name.startswith("conftest"):
|
||||
return MyCollector.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.name.startswith("conftest"):
|
||||
return MyCollector.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest(c.name + "::" + "xyz")
|
||||
|
|
|
@ -114,9 +114,9 @@ def dummy_yaml_custom_test(pytester: Pytester):
|
|||
"""
|
||||
import pytest
|
||||
|
||||
def pytest_collect_file(parent, fspath):
|
||||
if fspath.suffix == ".yaml" and fspath.name.startswith("test"):
|
||||
return YamlFile.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(parent, file_path):
|
||||
if file_path.suffix == ".yaml" and file_path.name.startswith("test"):
|
||||
return YamlFile.from_parent(path=file_path, parent=parent)
|
||||
|
||||
class YamlFile(pytest.File):
|
||||
def collect(self):
|
||||
|
|
|
@ -11,5 +11,5 @@ class CustomFile(pytest.File):
|
|||
yield CustomItem.from_parent(name="foo", parent=self)
|
||||
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
return CustomFile.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
return CustomFile.from_parent(path=file_path, parent=parent)
|
||||
|
|
|
@ -6,8 +6,8 @@ class MyFile(pytest.File):
|
|||
return [MyItem.from_parent(name="hello", parent=self)]
|
||||
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
return MyFile.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
return MyFile.from_parent(path=file_path, parent=parent)
|
||||
|
||||
|
||||
class MyItem(pytest.Item):
|
||||
|
|
|
@ -913,9 +913,9 @@ class TestConftestCustomization:
|
|||
return Loader()
|
||||
sys.meta_path.append(Finder())
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".narf":
|
||||
return Module.from_parent(path=fspath, parent=parent)"""
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".narf":
|
||||
return Module.from_parent(path=file_path, parent=parent)"""
|
||||
)
|
||||
pytester.makefile(
|
||||
".narf",
|
||||
|
|
|
@ -93,9 +93,9 @@ class TestCollector:
|
|||
import pytest
|
||||
class CustomFile(pytest.File):
|
||||
pass
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".xxx":
|
||||
return CustomFile.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".xxx":
|
||||
return CustomFile.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
)
|
||||
node = pytester.getpathnode(hello)
|
||||
|
@ -269,10 +269,10 @@ class TestCollectPluginHookRelay:
|
|||
wascalled = []
|
||||
|
||||
class Plugin:
|
||||
def pytest_collect_file(self, fspath: Path) -> None:
|
||||
if not fspath.name.startswith("."):
|
||||
def pytest_collect_file(self, file_path: Path) -> None:
|
||||
if not file_path.name.startswith("."):
|
||||
# Ignore hidden files, e.g. .testmondata.
|
||||
wascalled.append(fspath)
|
||||
wascalled.append(file_path)
|
||||
|
||||
pytester.makefile(".abc", "xyz")
|
||||
pytest.main(pytester.path, plugins=[Plugin()])
|
||||
|
@ -290,8 +290,8 @@ class TestPrunetraceback:
|
|||
pytester.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
def pytest_collect_file(fspath, parent):
|
||||
return MyFile.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
return MyFile.from_parent(path=file_path, parent=parent)
|
||||
class MyError(Exception):
|
||||
pass
|
||||
class MyFile(pytest.File):
|
||||
|
@ -417,9 +417,9 @@ class TestCustomConftests:
|
|||
import pytest
|
||||
class MyModule(pytest.Module):
|
||||
pass
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".py":
|
||||
return MyModule.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".py":
|
||||
return MyModule.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
)
|
||||
pytester.mkdir("sub")
|
||||
|
@ -435,9 +435,9 @@ class TestCustomConftests:
|
|||
import pytest
|
||||
class MyModule1(pytest.Module):
|
||||
pass
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".py":
|
||||
return MyModule1.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".py":
|
||||
return MyModule1.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
)
|
||||
conf1.replace(sub1.joinpath(conf1.name))
|
||||
|
@ -446,9 +446,9 @@ class TestCustomConftests:
|
|||
import pytest
|
||||
class MyModule2(pytest.Module):
|
||||
pass
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".py":
|
||||
return MyModule2.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".py":
|
||||
return MyModule2.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
)
|
||||
conf2.replace(sub2.joinpath(conf2.name))
|
||||
|
@ -537,9 +537,9 @@ class TestSession:
|
|||
class SpecialFile(pytest.File):
|
||||
def collect(self):
|
||||
return [SpecialItem.from_parent(name="check", parent=self)]
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.name == %r:
|
||||
return SpecialFile.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.name == %r:
|
||||
return SpecialFile.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
% p.name
|
||||
)
|
||||
|
@ -757,13 +757,13 @@ def test_matchnodes_two_collections_same_file(pytester: Pytester) -> None:
|
|||
config.pluginmanager.register(Plugin2())
|
||||
|
||||
class Plugin2(object):
|
||||
def pytest_collect_file(self, fspath, parent):
|
||||
if fspath.suffix == ".abc":
|
||||
return MyFile2.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(self, file_path, parent):
|
||||
if file_path.suffix == ".abc":
|
||||
return MyFile2.from_parent(path=file_path, parent=parent)
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".abc":
|
||||
return MyFile1.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".abc":
|
||||
return MyFile1.from_parent(path=file_path, parent=parent)
|
||||
|
||||
class MyFile1(pytest.File):
|
||||
def collect(self):
|
||||
|
|
|
@ -979,9 +979,9 @@ class TestNonPython:
|
|||
pytester.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == ".xyz":
|
||||
return MyItem.from_parent(name=fspath.name, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == ".xyz":
|
||||
return MyItem.from_parent(name=file_path.name, parent=parent)
|
||||
class MyItem(pytest.Item):
|
||||
def runtest(self):
|
||||
raise ValueError(42)
|
||||
|
@ -1430,9 +1430,9 @@ def test_fancy_items_regression(pytester: Pytester, run_and_parse: RunAndParse)
|
|||
NoFunItem.from_parent(name='b', parent=self),
|
||||
]
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
if fspath.suffix == '.py':
|
||||
return FunCollector.from_parent(path=fspath, parent=parent)
|
||||
def pytest_collect_file(file_path, parent):
|
||||
if file_path.suffix == '.py':
|
||||
return FunCollector.from_parent(path=file_path, parent=parent)
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
|
@ -1317,7 +1317,7 @@ def test_xfail_item(pytester: Pytester) -> None:
|
|||
def runtest(self):
|
||||
pytest.xfail("Expected Failure")
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
def pytest_collect_file(file_path, parent):
|
||||
return MyItem.from_parent(name="foo", parent=parent)
|
||||
"""
|
||||
)
|
||||
|
@ -1391,7 +1391,7 @@ def test_mark_xfail_item(pytester: Pytester) -> None:
|
|||
def runtest(self):
|
||||
assert False
|
||||
|
||||
def pytest_collect_file(fspath, parent):
|
||||
def pytest_collect_file(file_path, parent):
|
||||
return MyItem.from_parent(name="foo", parent=parent)
|
||||
"""
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue