diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index 4c5e668d2..9cb3fba40 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -936,7 +936,7 @@ pytest treats some global variables in a special manner when defined in a test m **Tutorial**: :ref:`customizing-test-collection` Can be declared in *conftest.py files* to exclude test directories or modules. -Needs to be ``list[str]``. +Needs to be a list of paths (``str``, :class:`pathlib.Path` or any :class:`os.PathLike`). .. code-block:: python diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 144f1c9d1..624fbd02f 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1445,9 +1445,7 @@ class Config: modpath = Path(mod.__file__).parent values: List[Path] = [] for relroot in relroots: - if isinstance(relroot, Path): - pass - elif isinstance(relroot, LEGACY_PATH): + if isinstance(relroot, os.PathLike): relroot = Path(relroot) else: relroot = relroot.replace("/", os.sep) diff --git a/testing/test_collection.py b/testing/test_collection.py index f015578e2..33087fd2e 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -367,12 +367,19 @@ class TestCustomConftests: def test_collectignore_exclude_on_option(self, pytester: Pytester) -> None: pytester.makeconftest( """ - # potentially avoid dependency on pylib - from _pytest.compat import legacy_path from pathlib import Path - collect_ignore = [legacy_path('hello'), 'test_world.py', Path('bye')] + + class MyPathLike: + def __init__(self, path): + self.path = path + def __fspath__(self): + return "path" + + collect_ignore = [MyPathLike('hello'), 'test_world.py', Path('bye')] + def pytest_addoption(parser): parser.addoption("--XX", action="store_true", default=False) + def pytest_configure(config): if config.getvalue("XX"): collect_ignore[:] = []