Merge pull request #9780 from bluetech/restore-confcutdir-behavior
config: restore pre-pytest 7.1.0 confcutdir exclusion behavior
This commit is contained in:
commit
f196701cc1
|
@ -0,0 +1 @@
|
||||||
|
Fixed a regression in pytest 7.1.0 where some conftest.py files outside of the source tree (e.g. in the `site-packages` directory) were not picked up.
|
|
@ -540,11 +540,7 @@ class PytestPluginManager(PluginManager):
|
||||||
"""
|
"""
|
||||||
if self._confcutdir is None:
|
if self._confcutdir is None:
|
||||||
return True
|
return True
|
||||||
try:
|
return path not in self._confcutdir.parents
|
||||||
path.relative_to(self._confcutdir)
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _try_load_conftest(
|
def _try_load_conftest(
|
||||||
self, anchor: Path, importmode: Union[str, ImportMode], rootpath: Path
|
self, anchor: Path, importmode: Union[str, ImportMode], rootpath: Path
|
||||||
|
|
|
@ -252,6 +252,34 @@ def test_conftest_confcutdir(pytester: Pytester) -> None:
|
||||||
result.stdout.no_fnmatch_line("*warning: could not load initial*")
|
result.stdout.no_fnmatch_line("*warning: could not load initial*")
|
||||||
|
|
||||||
|
|
||||||
|
def test_installed_conftest_is_picked_up(pytester: Pytester, tmp_path: Path) -> None:
|
||||||
|
"""When using `--pyargs` to run tests in an installed packages (located e.g.
|
||||||
|
in a site-packages in the PYTHONPATH), conftest files in there are picked
|
||||||
|
up.
|
||||||
|
|
||||||
|
Regression test for #9767.
|
||||||
|
"""
|
||||||
|
# pytester dir - the source tree.
|
||||||
|
# tmp_path - the simulated site-packages dir (not in source tree).
|
||||||
|
|
||||||
|
pytester.syspathinsert(tmp_path)
|
||||||
|
pytester.makepyprojecttoml("[tool.pytest.ini_options]")
|
||||||
|
tmp_path.joinpath("foo").mkdir()
|
||||||
|
tmp_path.joinpath("foo", "__init__.py").touch()
|
||||||
|
tmp_path.joinpath("foo", "conftest.py").write_text(
|
||||||
|
textwrap.dedent(
|
||||||
|
"""\
|
||||||
|
import pytest
|
||||||
|
@pytest.fixture
|
||||||
|
def fix(): return None
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
tmp_path.joinpath("foo", "test_it.py").write_text("def test_it(fix): pass")
|
||||||
|
result = pytester.runpytest("--pyargs", "foo")
|
||||||
|
assert result.ret == 0
|
||||||
|
|
||||||
|
|
||||||
def test_conftest_symlink(pytester: Pytester) -> None:
|
def test_conftest_symlink(pytester: Pytester) -> None:
|
||||||
"""`conftest.py` discovery follows normal path resolution and does not resolve symlinks."""
|
"""`conftest.py` discovery follows normal path resolution and does not resolve symlinks."""
|
||||||
# Structure:
|
# Structure:
|
||||||
|
|
Loading…
Reference in New Issue