Skip to content

Commit

Permalink
config: stop resolving symlinks in conftest paths
Browse files Browse the repository at this point in the history
This became the wrong thing to do since
322190f.
  • Loading branch information
bluetech committed Jan 9, 2022
1 parent d98b695 commit f80502e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 10 additions & 0 deletions changelog/TBD.bugfix.rst
@@ -0,0 +1,10 @@
Symbolic link components are no longer resolved in conftest paths.
This means that if a conftest appears twice in collection tree, using symlinks, it will be executed twice.
For example, given

tests/real/conftest.py
tests/real/test_it.py
tests/link -> tests/real

running ``pytest tests`` now imports the conftest twice, once as ``tests/real/conftest.py`` and once as ``tests/link/conftest.py``.
This is a fix to match a similar change made to test collection itself in pytest 6.0 (see :pull:`6523` for details).
11 changes: 2 additions & 9 deletions src/_pytest/config/__init__.py
Expand Up @@ -592,15 +592,8 @@ def _rget_with_confmod(
def _importconftest(
self, conftestpath: Path, importmode: Union[str, ImportMode], rootpath: Path
) -> types.ModuleType:
# Use a resolved Path object as key to avoid loading the same conftest
# twice with build systems that create build directories containing
# symlinks to actual files.
# Using Path().resolve() is better than py.path.realpath because
# it resolves to the correct path/drive in case-insensitive file systems (#5792)
key = conftestpath.resolve()

with contextlib.suppress(KeyError):
return self._conftestpath2mod[key]
return self._conftestpath2mod[conftestpath]

pkgpath = resolve_package_path(conftestpath)
if pkgpath is None:
Expand All @@ -616,7 +609,7 @@ def _importconftest(
self._check_non_top_pytest_plugins(mod, conftestpath)

self._conftest_plugins.add(mod)
self._conftestpath2mod[key] = mod
self._conftestpath2mod[conftestpath] = mod
dirpath = conftestpath.parent
if dirpath in self._dirpath2confmods:
for path, mods in self._dirpath2confmods.items():
Expand Down

0 comments on commit f80502e

Please sign in to comment.