diff --git a/src/_pytest/config/compat.py b/src/_pytest/config/compat.py index 8253ce549..88d0f23bb 100644 --- a/src/_pytest/config/compat.py +++ b/src/_pytest/config/compat.py @@ -12,7 +12,7 @@ from _pytest.nodes import _check_path imply_paths_hooks = { "pytest_ignore_collect": ("collection_path", "path"), "pytest_collect_file": ("file_path", "path"), - "pytest_pycollect_makemodule": ("fspath", "path"), + "pytest_pycollect_makemodule": ("module_path", "path"), "pytest_report_header": ("startpath", "startdir"), "pytest_report_collectionfinish": ("startpath", "startdir"), } diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index f2983cefd..59f9d11fc 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -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``. diff --git a/src/_pytest/python.py b/src/_pytest/python.py index b2548e127..ff623625b 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -204,7 +204,7 @@ def pytest_collect_file(file_path: Path, parent: nodes.Collector) -> Optional["M return None ihook = parent.session.gethookproxy(file_path) module: Module = ihook.pytest_pycollect_makemodule( - fspath=file_path, parent=parent + module_path=file_path, parent=parent ) return module return None @@ -215,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 diff --git a/testing/python/collect.py b/testing/python/collect.py index f6ae6d3c4..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")