Merge pull request #11795 from lesteve/improve-assert-mod-not-in-mods-error-message

Improve assert mod not in mods error message
This commit is contained in:
Ran Benita 2024-01-14 13:39:14 +02:00 committed by GitHub
commit 2bb0eca347
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -664,7 +664,12 @@ class PytestPluginManager(PluginManager):
if dirpath in self._dirpath2confmods: if dirpath in self._dirpath2confmods:
for path, mods in self._dirpath2confmods.items(): for path, mods in self._dirpath2confmods.items():
if dirpath in path.parents or path == dirpath: if dirpath in path.parents or path == dirpath:
assert mod not in mods if mod in mods:
raise AssertionError(
f"While trying to load conftest path {str(conftestpath)}, "
f"found that the module {mod} is already loaded with path {mod.__file__}. "
"This is not supposed to happen. Please report this issue to pytest."
)
mods.append(mod) mods.append(mod)
self.trace(f"loading conftestmodule {mod!r}") self.trace(f"loading conftestmodule {mod!r}")
self.consider_conftest(mod, registration_name=conftestpath_plugin_name) self.consider_conftest(mod, registration_name=conftestpath_plugin_name)