Skip to content

Commit 2bb0eca

Browse files
authored
Merge pull request #11795 from lesteve/improve-assert-mod-not-in-mods-error-message
Improve assert mod not in mods error message
2 parents c6ed864 + 1c9d683 commit 2bb0eca

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/_pytest/config/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,12 @@ def _importconftest(
664664
if dirpath in self._dirpath2confmods:
665665
for path, mods in self._dirpath2confmods.items():
666666
if dirpath in path.parents or path == dirpath:
667-
assert mod not in mods
667+
if mod in mods:
668+
raise AssertionError(
669+
f"While trying to load conftest path {str(conftestpath)}, "
670+
f"found that the module {mod} is already loaded with path {mod.__file__}. "
671+
"This is not supposed to happen. Please report this issue to pytest."
672+
)
668673
mods.append(mod)
669674
self.trace(f"loading conftestmodule {mod!r}")
670675
self.consider_conftest(mod, registration_name=conftestpath_plugin_name)

0 commit comments

Comments
 (0)