Skip to content

Commit 0ef8823

Browse files
committed
config: stop resolving symlinks in conftest paths
This became the wrong thing to do since 322190f.
1 parent d98b695 commit 0ef8823

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

changelog/9493.bugfix.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Symbolic link components are no longer resolved in conftest paths.
2+
This means that if a conftest appears twice in collection tree, using symlinks, it will be executed twice.
3+
For example, given
4+
5+
tests/real/conftest.py
6+
tests/real/test_it.py
7+
tests/link -> tests/real
8+
9+
running ``pytest tests`` now imports the conftest twice, once as ``tests/real/conftest.py`` and once as ``tests/link/conftest.py``.
10+
This is a fix to match a similar change made to test collection itself in pytest 6.0 (see :pull:`6523` for details).

src/_pytest/config/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,8 @@ def _rget_with_confmod(
592592
def _importconftest(
593593
self, conftestpath: Path, importmode: Union[str, ImportMode], rootpath: Path
594594
) -> types.ModuleType:
595-
# Use a resolved Path object as key to avoid loading the same conftest
596-
# twice with build systems that create build directories containing
597-
# symlinks to actual files.
598-
# Using Path().resolve() is better than py.path.realpath because
599-
# it resolves to the correct path/drive in case-insensitive file systems (#5792)
600-
key = conftestpath.resolve()
601-
602595
with contextlib.suppress(KeyError):
603-
return self._conftestpath2mod[key]
596+
return self._conftestpath2mod[conftestpath]
604597

605598
pkgpath = resolve_package_path(conftestpath)
606599
if pkgpath is None:
@@ -616,7 +609,7 @@ def _importconftest(
616609
self._check_non_top_pytest_plugins(mod, conftestpath)
617610

618611
self._conftest_plugins.add(mod)
619-
self._conftestpath2mod[key] = mod
612+
self._conftestpath2mod[conftestpath] = mod
620613
dirpath = conftestpath.parent
621614
if dirpath in self._dirpath2confmods:
622615
for path, mods in self._dirpath2confmods.items():

0 commit comments

Comments
 (0)