From f80502e32524026bcf6c4d9f35c62c2ed47f062b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 9 Jan 2022 01:40:57 +0200 Subject: [PATCH] config: stop resolving symlinks in conftest paths This became the wrong thing to do since 322190fd84e1b86d7b9a2d71f086445ca80c39b3. --- changelog/TBD.bugfix.rst | 10 ++++++++++ src/_pytest/config/__init__.py | 11 ++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 changelog/TBD.bugfix.rst diff --git a/changelog/TBD.bugfix.rst b/changelog/TBD.bugfix.rst new file mode 100644 index 00000000000..d99c80b7d2c --- /dev/null +++ b/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). diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index a6a22d2b913..b75a675b6d8 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -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: @@ -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():