diff --git a/changelog/8144.feature.rst b/changelog/8144.feature.rst index 01f40e215..effd4bf84 100644 --- a/changelog/8144.feature.rst +++ b/changelog/8144.feature.rst @@ -1,7 +1,7 @@ The following hooks now receive an additional ``pathlib.Path`` argument, equivalent to an existing ``py.path.local`` argument: -- :func:`pytest_ignore_collect <_pytest.hookspec.pytest_ignore_collect>` - The ``fspath`` parameter (equivalent to existing ``path`` parameter). -- :func:`pytest_collect_file <_pytest.hookspec.pytest_collect_file>` - The ``fspath`` parameter (equivalent to existing ``path`` parameter). -- :func:`pytest_pycollect_makemodule <_pytest.hookspec.pytest_pycollect_makemodule>` - The ``fspath`` parameter (equivalent to existing ``path`` parameter). -- :func:`pytest_report_header <_pytest.hookspec.pytest_report_header>` - The ``startpath`` parameter (equivalent to existing ``startdir`` parameter). -- :func:`pytest_report_collectionfinish <_pytest.hookspec.pytest_report_collectionfinish>` - The ``startpath`` parameter (equivalent to existing ``startdir`` parameter). +- :func:`pytest_ignore_collect <_pytest.hookspec.pytest_ignore_collect>` - The ``collection_path`` parameter (equivalent to existing ``path`` parameter). +- :func:`pytest_collect_file <_pytest.hookspec.pytest_collect_file>` - The ``file_path`` parameter (equivalent to existing ``path`` parameter). +- :func:`pytest_pycollect_makemodule <_pytest.hookspec.pytest_pycollect_makemodule>` - The ``module_path`` parameter (equivalent to existing ``path`` parameter). +- :func:`pytest_report_header <_pytest.hookspec.pytest_report_header>` - The ``start_path`` parameter (equivalent to existing ``startdir`` parameter). +- :func:`pytest_report_collectionfinish <_pytest.hookspec.pytest_report_collectionfinish>` - The ``start_path`` parameter (equivalent to existing ``startdir`` parameter). diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 7aff6cbcf..84f7b8fa8 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -66,11 +66,11 @@ drop any other usage of the ``py`` library if possible. In order to support the transition from ``py.path.local`` to :mod:`pathlib`, the following hooks now receive additional arguments: -* :func:`pytest_ignore_collect(fspath: pathlib.Path) <_pytest.hookspec.pytest_ignore_collect>` instead of ``path`` -* :func:`pytest_collect_file(fspath: pathlib.Path) <_pytest.hookspec.pytest_collect_file>` instead of ``path`` -* :func:`pytest_pycollect_makemodule(fspath: pathlib.Path) <_pytest.hookspec.pytest_pycollect_makemodule>` instead of ``path`` -* :func:`pytest_report_header(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_header>` instead of ``startdir`` -* :func:`pytest_report_collectionfinish(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_collectionfinish>` instead of ``startdir`` +* :func:`pytest_ignore_collect(collection_path: pathlib.Path) <_pytest.hookspec.pytest_ignore_collect>` as equivalent to ``path`` +* :func:`pytest_collect_file(file_path: pathlib.Path) <_pytest.hookspec.pytest_collect_file>` as equivalent to ``path`` +* :func:`pytest_pycollect_makemodule(module_path: pathlib.Path) <_pytest.hookspec.pytest_pycollect_makemodule>` as equivalent to ``path`` +* :func:`pytest_report_header(start_path: pathlib.Path) <_pytest.hookspec.pytest_report_header>` as equivalent to ``startdir`` +* :func:`pytest_report_collectionfinish(start_path: pathlib.Path) <_pytest.hookspec.pytest_report_collectionfinish>` as equivalent to ``startdir`` The accompanying ``py.path.local`` based paths have been deprecated: plugins which manually invoke those hooks should only pass the new ``pathlib.Path`` arguments, and users should change their hook implementations to use the new ``pathlib.Path`` arguments. diff --git a/src/_pytest/config/compat.py b/src/_pytest/config/compat.py index 731641dde..8f82dd9f9 100644 --- a/src/_pytest/config/compat.py +++ b/src/_pytest/config/compat.py @@ -10,11 +10,11 @@ from _pytest.nodes import _check_path # hookname: (Path, LEGACY_PATH) imply_paths_hooks = { - "pytest_ignore_collect": ("fspath", "path"), - "pytest_collect_file": ("fspath", "path"), - "pytest_pycollect_makemodule": ("fspath", "path"), - "pytest_report_header": ("startpath", "startdir"), - "pytest_report_collectionfinish": ("startpath", "startdir"), + "pytest_ignore_collect": ("collection_path", "path"), + "pytest_collect_file": ("file_path", "path"), + "pytest_pycollect_makemodule": ("module_path", "path"), + "pytest_report_header": ("start_path", "startdir"), + "pytest_report_collectionfinish": ("start_path", "startdir"), } diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index baba713e1..0784f431b 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -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 diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index ee9553e0f..b65be9815 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -262,7 +262,7 @@ def pytest_collection_finish(session: "Session") -> None: @hookspec(firstresult=True) def pytest_ignore_collect( - fspath: Path, path: "LEGACY_PATH", config: "Config" + collection_path: Path, path: "LEGACY_PATH", config: "Config" ) -> Optional[bool]: """Return True to prevent considering this path for collection. @@ -271,29 +271,29 @@ def pytest_ignore_collect( Stops at first non-None result, see :ref:`firstresult`. - :param pathlib.Path fspath: The path to analyze. + :param pathlib.Path collection_path : The path to analyze. :param LEGACY_PATH path: The path to analyze (deprecated). :param pytest.Config config: The pytest config object. .. versionchanged:: 7.0.0 - The ``fspath`` parameter was added as a :class:`pathlib.Path` + The ``collection_path`` parameter was added as a :class:`pathlib.Path` equivalent of the ``path`` parameter. The ``path`` parameter has been deprecated. """ 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. """ @@ -337,7 +337,7 @@ def pytest_make_collect_report(collector: "Collector") -> "Optional[CollectRepor @hookspec(firstresult=True) def pytest_pycollect_makemodule( - fspath: Path, path: "LEGACY_PATH", parent + module_path: Path, path: "LEGACY_PATH", parent ) -> Optional["Module"]: """Return a Module collector or None for the given path. @@ -347,11 +347,11 @@ def pytest_pycollect_makemodule( Stops at first non-None result, see :ref:`firstresult`. - :param pathlib.Path fspath: The path of the module to collect. + :param pathlib.Path module_path: The path of the module to collect. :param LEGACY_PATH path: The path of the module to collect (deprecated). .. versionchanged:: 7.0.0 - The ``fspath`` parameter was added as a :class:`pathlib.Path` + The ``module_path`` parameter was added as a :class:`pathlib.Path` equivalent of the ``path`` parameter. The ``path`` parameter has been deprecated in favor of ``fspath``. @@ -674,12 +674,12 @@ def pytest_assertion_pass(item: "Item", lineno: int, orig: str, expl: str) -> No def pytest_report_header( - config: "Config", startpath: Path, startdir: "LEGACY_PATH" + config: "Config", start_path: Path, startdir: "LEGACY_PATH" ) -> Union[str, List[str]]: """Return a string or list of strings to be displayed as header info for terminal reporting. :param pytest.Config config: The pytest config object. - :param Path startpath: The starting dir. + :param Path start_path: The starting dir. :param LEGACY_PATH startdir: The starting dir (deprecated). .. note:: @@ -696,7 +696,7 @@ def pytest_report_header( :ref:`discovers plugins during startup `. .. versionchanged:: 7.0.0 - The ``startpath`` parameter was added as a :class:`pathlib.Path` + The ``start_path`` parameter was added as a :class:`pathlib.Path` equivalent of the ``startdir`` parameter. The ``startdir`` parameter has been deprecated. """ @@ -704,7 +704,7 @@ def pytest_report_header( def pytest_report_collectionfinish( config: "Config", - startpath: Path, + start_path: Path, startdir: "LEGACY_PATH", items: Sequence["Item"], ) -> Union[str, List[str]]: @@ -716,7 +716,7 @@ def pytest_report_collectionfinish( .. versionadded:: 3.2 :param pytest.Config config: The pytest config object. - :param Path startpath: The starting dir. + :param Path start_path: The starting dir. :param LEGACY_PATH startdir: The starting dir (deprecated). :param items: List of pytest items that are going to be executed; this list should not be modified. @@ -728,7 +728,7 @@ def pytest_report_collectionfinish( :ref:`trylast=True `. .. versionchanged:: 7.0.0 - The ``startpath`` parameter was added as a :class:`pathlib.Path` + The ``start_path`` parameter was added as a :class:`pathlib.Path` equivalent of the ``startdir`` parameter. The ``startdir`` parameter has been deprecated. """ diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 5c33fc644..57407fe54 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -372,31 +372,31 @@ def _in_venv(path: Path) -> bool: return any(fname.name in activates for fname in bindir.iterdir()) -def pytest_ignore_collect(fspath: Path, config: Config) -> Optional[bool]: +def pytest_ignore_collect(collection_path: Path, config: Config) -> Optional[bool]: ignore_paths = config._getconftest_pathlist( - "collect_ignore", path=fspath.parent, rootpath=config.rootpath + "collect_ignore", path=collection_path.parent, rootpath=config.rootpath ) ignore_paths = ignore_paths or [] excludeopt = config.getoption("ignore") if excludeopt: ignore_paths.extend(absolutepath(x) for x in excludeopt) - if fspath in ignore_paths: + if collection_path in ignore_paths: return True ignore_globs = config._getconftest_pathlist( - "collect_ignore_glob", path=fspath.parent, rootpath=config.rootpath + "collect_ignore_glob", path=collection_path.parent, rootpath=config.rootpath ) ignore_globs = ignore_globs or [] excludeglobopt = config.getoption("ignore_glob") if excludeglobopt: ignore_globs.extend(absolutepath(x) for x in excludeglobopt) - if any(fnmatch.fnmatch(str(fspath), str(glob)) for glob in ignore_globs): + if any(fnmatch.fnmatch(str(collection_path), str(glob)) for glob in ignore_globs): return True allow_in_venv = config.getoption("collect_in_virtualenv") - if not allow_in_venv and _in_venv(fspath): + if not allow_in_venv and _in_venv(collection_path): return True return None @@ -557,7 +557,7 @@ class Session(nodes.FSCollector): return False fspath = Path(direntry.path) ihook = self.gethookproxy(fspath.parent) - if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): + if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config): return False norecursepatterns = self.config.getini("norecursedirs") if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns): @@ -574,7 +574,7 @@ class Session(nodes.FSCollector): ) ihook = self.gethookproxy(fspath) if not self.isinitpath(fspath): - if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): + if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config): return () if handle_dupes: @@ -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( diff --git a/src/_pytest/python.py b/src/_pytest/python.py index d9fccde9a..ff623625b 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -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( + module_path=file_path, parent=parent + ) return module return None @@ -213,11 +215,11 @@ def path_matches_patterns(path: Path, patterns: Iterable[str]) -> bool: return any(fnmatch_ex(pattern, path) for pattern in patterns) -def pytest_pycollect_makemodule(fspath: Path, parent) -> "Module": - if fspath.name == "__init__.py": - pkg: Package = Package.from_parent(parent, path=fspath) +def pytest_pycollect_makemodule(module_path: Path, parent) -> "Module": + if module_path.name == "__init__.py": + pkg: Package = Package.from_parent(parent, path=module_path) return pkg - mod: Module = Module.from_parent(parent, path=fspath) + mod: Module = Module.from_parent(parent, path=module_path) return mod @@ -676,7 +678,7 @@ class Package(Module): return False fspath = Path(direntry.path) ihook = self.session.gethookproxy(fspath.parent) - if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): + if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config): return False norecursepatterns = self.config.getini("norecursedirs") if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns): @@ -693,7 +695,7 @@ class Package(Module): ) ihook = self.session.gethookproxy(fspath) if not self.session.isinitpath(fspath): - if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): + if ihook.pytest_ignore_collect(collection_path=fspath, config=self.config): return () if handle_dupes: @@ -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 diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 057e89e6b..ccbd84d7d 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -702,7 +702,7 @@ class TerminalReporter: msg += " -- " + str(sys.executable) self.write_line(msg) lines = self.config.hook.pytest_report_header( - config=self.config, startpath=self.startpath + config=self.config, start_path=self.startpath ) self._write_report_lines_from_hooks(lines) @@ -738,7 +738,7 @@ class TerminalReporter: lines = self.config.hook.pytest_report_collectionfinish( config=self.config, - startpath=self.startpath, + start_path=self.startpath, items=session.items, ) self._write_report_lines_from_hooks(lines) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 30a507686..bfd1fe6e6 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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") diff --git a/testing/conftest.py b/testing/conftest.py index 63817b9ad..107aad86b 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -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): diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 38af26d58..7d7e6d312 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -160,10 +160,10 @@ def test_raising_unittest_skiptest_during_collection_is_deprecated( @pytest.mark.parametrize("hooktype", ["hook", "ihook"]) -def test_hookproxy_warnings_for_fspath(tmp_path, hooktype, request): +def test_hookproxy_warnings_for_pathlib(tmp_path, hooktype, request): path = legacy_path(tmp_path) - PATH_WARN_MATCH = r".*path: py\.path\.local\) argument is deprecated, please use \(fspath: pathlib\.Path.*" + PATH_WARN_MATCH = r".*path: py\.path\.local\) argument is deprecated, please use \(collection_path: pathlib\.Path.*" if hooktype == "ihook": hooks = request.node.ihook else: @@ -171,20 +171,22 @@ def test_hookproxy_warnings_for_fspath(tmp_path, hooktype, request): with pytest.warns(PytestDeprecationWarning, match=PATH_WARN_MATCH) as r: l1 = sys._getframe().f_lineno - hooks.pytest_ignore_collect(config=request.config, path=path, fspath=tmp_path) + hooks.pytest_ignore_collect( + config=request.config, path=path, collection_path=tmp_path + ) l2 = sys._getframe().f_lineno (record,) = r assert record.filename == __file__ assert l1 < record.lineno < l2 - hooks.pytest_ignore_collect(config=request.config, fspath=tmp_path) + hooks.pytest_ignore_collect(config=request.config, collection_path=tmp_path) # Passing entirely *different* paths is an outright error. with pytest.raises(ValueError, match=r"path.*fspath.*need to be equal"): with pytest.warns(PytestDeprecationWarning, match=PATH_WARN_MATCH) as r: hooks.pytest_ignore_collect( - config=request.config, path=path, fspath=Path("/bla/bla") + config=request.config, path=path, collection_path=Path("/bla/bla") ) diff --git a/testing/example_scripts/collect/package_infinite_recursion/conftest.py b/testing/example_scripts/collect/package_infinite_recursion/conftest.py index d9e7a89bd..973ccc0c0 100644 --- a/testing/example_scripts/collect/package_infinite_recursion/conftest.py +++ b/testing/example_scripts/collect/package_infinite_recursion/conftest.py @@ -1,2 +1,2 @@ -def pytest_ignore_collect(fspath): +def pytest_ignore_collect(collection_path): return False diff --git a/testing/example_scripts/fixtures/custom_item/conftest.py b/testing/example_scripts/fixtures/custom_item/conftest.py index 1b3940e95..a7a5e9db8 100644 --- a/testing/example_scripts/fixtures/custom_item/conftest.py +++ b/testing/example_scripts/fixtures/custom_item/conftest.py @@ -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) diff --git a/testing/example_scripts/issue88_initial_file_multinodes/conftest.py b/testing/example_scripts/issue88_initial_file_multinodes/conftest.py index 7227a53b7..cb8f5d671 100644 --- a/testing/example_scripts/issue88_initial_file_multinodes/conftest.py +++ b/testing/example_scripts/issue88_initial_file_multinodes/conftest.py @@ -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): diff --git a/testing/plugins_integration/requirements.txt b/testing/plugins_integration/requirements.txt index 096f91dd0..fbc735de3 100644 --- a/testing/plugins_integration/requirements.txt +++ b/testing/plugins_integration/requirements.txt @@ -4,7 +4,7 @@ pytest-asyncio==0.16.0 pytest-bdd==5.0.0 pytest-cov==3.0.0 pytest-django==4.4.0 -pytest-flakes==4.0.4 +pytest-flakes==4.0.5 pytest-html==3.1.1 pytest-mock==3.6.1 pytest-rerunfailures==10.2 diff --git a/testing/python/collect.py b/testing/python/collect.py index 35a2a0ec5..ac3edd395 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -809,9 +809,9 @@ class TestConftestCustomization: import pytest class MyModule(pytest.Module): pass - def pytest_pycollect_makemodule(fspath, parent): - if fspath.name == "test_xyz.py": - return MyModule.from_parent(path=fspath, parent=parent) + def pytest_pycollect_makemodule(module_path, parent): + if module_path.name == "test_xyz.py": + return MyModule.from_parent(path=module_path, parent=parent) """ ) pytester.makepyfile("def test_some(): pass") @@ -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", diff --git a/testing/test_collection.py b/testing/test_collection.py index 6d30a8a7a..6fd9a708b 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -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): @@ -333,8 +333,8 @@ class TestCustomConftests: def test_ignore_collect_path(self, pytester: Pytester) -> None: pytester.makeconftest( """ - def pytest_ignore_collect(fspath, config): - return fspath.name.startswith("x") or fspath.name == "test_one.py" + def pytest_ignore_collect(collection_path, config): + return collection_path.name.startswith("x") or collection_path.name == "test_one.py" """ ) sub = pytester.mkdir("xy123") @@ -349,7 +349,7 @@ class TestCustomConftests: def test_ignore_collect_not_called_on_argument(self, pytester: Pytester) -> None: pytester.makeconftest( """ - def pytest_ignore_collect(fspath, config): + def pytest_ignore_collect(collection_path, config): return True """ ) @@ -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): diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 3ccdeb964..64c1014a5 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -667,7 +667,7 @@ def test_hook_proxy(pytester: Pytester) -> None: "root/demo-0/test_foo1.py": "def test1(): pass", "root/demo-a/test_foo2.py": "def test1(): pass", "root/demo-a/conftest.py": """\ - def pytest_ignore_collect(fspath, config): + def pytest_ignore_collect(collection_path, config): return True """, "root/demo-b/test_foo3.py": "def test1(): pass", diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index ae8aa8fd3..02531e814 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -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) """ ) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 308c91abe..a0b5cddab 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -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) """ ) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 32f32ff5e..23f597e33 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1035,7 +1035,7 @@ class TestTerminalFunctional: def test_report_collectionfinish_hook(self, pytester: Pytester, params) -> None: pytester.makeconftest( """ - def pytest_report_collectionfinish(config, startpath, items): + def pytest_report_collectionfinish(config, start_path, items): return [f'hello from hook: {len(items)} items'] """ ) @@ -1461,8 +1461,8 @@ class TestGenericReporting: ) pytester.mkdir("a").joinpath("conftest.py").write_text( """ -def pytest_report_header(config, startpath): - return ["line1", str(startpath)] +def pytest_report_header(config, start_path): + return ["line1", str(start_path)] """ ) result = pytester.runpytest("a")