Skip to content

Commit 44c0319

Browse files
fcharraslesteve
andcommitted
Fix key formating divergence when inspecting plugin dictionary.
Fix #27806 Co-authored-by: Loïc Estève <[email protected]>
1 parent 047ba83 commit 44c0319

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/_pytest/config/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ def _rget_with_confmod(
639639
def _importconftest(
640640
self, conftestpath: Path, importmode: Union[str, ImportMode], rootpath: Path
641641
) -> types.ModuleType:
642-
existing = self.get_plugin(str(conftestpath))
642+
conftest_registration_name = os.path.normcase(os.path.normpath(conftestpath))
643+
644+
existing = self.get_plugin(conftest_registration_name)
643645
if existing is not None:
644646
return cast(types.ModuleType, existing)
645647

@@ -664,7 +666,7 @@ def _importconftest(
664666
assert mod not in mods
665667
mods.append(mod)
666668
self.trace(f"loading conftestmodule {mod!r}")
667-
self.consider_conftest(mod)
669+
self.consider_conftest(mod, name=conftest_registration_name)
668670
return mod
669671

670672
def _check_non_top_pytest_plugins(
@@ -744,9 +746,9 @@ def consider_pluginarg(self, arg: str) -> None:
744746
del self._name2plugin["pytest_" + name]
745747
self.import_plugin(arg, consider_entry_points=True)
746748

747-
def consider_conftest(self, conftestmodule: types.ModuleType) -> None:
749+
def consider_conftest(self, conftestmodule: types.ModuleType, name: str) -> None:
748750
""":meta private:"""
749-
self.register(conftestmodule, name=conftestmodule.__file__)
751+
self.register(conftestmodule, name=name)
750752

751753
def consider_env(self) -> None:
752754
""":meta private:"""

testing/test_conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:
212212
subconftest.touch()
213213
pm = PytestPluginManager()
214214
conftest_setinitial(pm, [sub.parent], confcutdir=pytester.path)
215-
key = subconftest.resolve()
215+
key = os.path.normcase(os.path.normpath(subconftest.resolve()))
216216
if name not in ("whatever", ".dotdir"):
217-
assert pm.has_plugin(str(key))
217+
assert pm.has_plugin(key)
218218
assert len(set(pm.get_plugins()) - {pm}) == 1
219219
else:
220-
assert not pm.has_plugin(str(key))
220+
assert not pm.has_plugin(key)
221221
assert len(set(pm.get_plugins()) - {pm}) == 0
222222

223223

testing/test_pluginmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def test_consider_conftest_deps(
368368
pytester.makepyfile("pytest_plugins='xyz'"), root=pytester.path
369369
)
370370
with pytest.raises(ImportError):
371-
pytestpm.consider_conftest(mod)
371+
pytestpm.consider_conftest(mod, name=str(mod.__file__))
372372

373373

374374
class TestPytestPluginManagerBootstrapming:

0 commit comments

Comments
 (0)