Rename pytest_pycollect_makemodule fspath parameter to module_path

This commit is contained in:
Bruno Oliveira 2021-12-01 17:53:15 -03:00
parent 714d7f430a
commit 5288588971
4 changed files with 12 additions and 12 deletions

View File

@ -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"),
}

View File

@ -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``.

View File

@ -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

View File

@ -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")