Rename pytest_pycollect_makemodule fspath parameter to module_path
This commit is contained in:
parent
714d7f430a
commit
5288588971
|
@ -12,7 +12,7 @@ from _pytest.nodes import _check_path
|
||||||
imply_paths_hooks = {
|
imply_paths_hooks = {
|
||||||
"pytest_ignore_collect": ("collection_path", "path"),
|
"pytest_ignore_collect": ("collection_path", "path"),
|
||||||
"pytest_collect_file": ("file_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_header": ("startpath", "startdir"),
|
||||||
"pytest_report_collectionfinish": ("startpath", "startdir"),
|
"pytest_report_collectionfinish": ("startpath", "startdir"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,7 @@ def pytest_make_collect_report(collector: "Collector") -> "Optional[CollectRepor
|
||||||
|
|
||||||
@hookspec(firstresult=True)
|
@hookspec(firstresult=True)
|
||||||
def pytest_pycollect_makemodule(
|
def pytest_pycollect_makemodule(
|
||||||
fspath: Path, path: "LEGACY_PATH", parent
|
module_path: Path, path: "LEGACY_PATH", parent
|
||||||
) -> Optional["Module"]:
|
) -> Optional["Module"]:
|
||||||
"""Return a Module collector or None for the given path.
|
"""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`.
|
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).
|
:param LEGACY_PATH path: The path of the module to collect (deprecated).
|
||||||
|
|
||||||
.. versionchanged:: 7.0.0
|
.. 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.
|
equivalent of the ``path`` parameter.
|
||||||
|
|
||||||
The ``path`` parameter has been deprecated in favor of ``fspath``.
|
The ``path`` parameter has been deprecated in favor of ``fspath``.
|
||||||
|
|
|
@ -204,7 +204,7 @@ def pytest_collect_file(file_path: Path, parent: nodes.Collector) -> Optional["M
|
||||||
return None
|
return None
|
||||||
ihook = parent.session.gethookproxy(file_path)
|
ihook = parent.session.gethookproxy(file_path)
|
||||||
module: Module = ihook.pytest_pycollect_makemodule(
|
module: Module = ihook.pytest_pycollect_makemodule(
|
||||||
fspath=file_path, parent=parent
|
module_path=file_path, parent=parent
|
||||||
)
|
)
|
||||||
return module
|
return module
|
||||||
return None
|
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)
|
return any(fnmatch_ex(pattern, path) for pattern in patterns)
|
||||||
|
|
||||||
|
|
||||||
def pytest_pycollect_makemodule(fspath: Path, parent) -> "Module":
|
def pytest_pycollect_makemodule(module_path: Path, parent) -> "Module":
|
||||||
if fspath.name == "__init__.py":
|
if module_path.name == "__init__.py":
|
||||||
pkg: Package = Package.from_parent(parent, path=fspath)
|
pkg: Package = Package.from_parent(parent, path=module_path)
|
||||||
return pkg
|
return pkg
|
||||||
mod: Module = Module.from_parent(parent, path=fspath)
|
mod: Module = Module.from_parent(parent, path=module_path)
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -809,9 +809,9 @@ class TestConftestCustomization:
|
||||||
import pytest
|
import pytest
|
||||||
class MyModule(pytest.Module):
|
class MyModule(pytest.Module):
|
||||||
pass
|
pass
|
||||||
def pytest_pycollect_makemodule(fspath, parent):
|
def pytest_pycollect_makemodule(module_path, parent):
|
||||||
if fspath.name == "test_xyz.py":
|
if module_path.name == "test_xyz.py":
|
||||||
return MyModule.from_parent(path=fspath, parent=parent)
|
return MyModule.from_parent(path=module_path, parent=parent)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
pytester.makepyfile("def test_some(): pass")
|
pytester.makepyfile("def test_some(): pass")
|
||||||
|
|
Loading…
Reference in New Issue