From 1c9d6834fdd7343397993703f3eb82e1460c56fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Wed, 10 Jan 2024 06:35:13 +0100 Subject: [PATCH] Improve assert mod not in mods error message [ran: tweaked message, made the formatting lazy] --- src/_pytest/config/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 85ae6dddfeb..dc018ce2a4f 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -664,7 +664,12 @@ def _importconftest( if dirpath in self._dirpath2confmods: for path, mods in self._dirpath2confmods.items(): 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) self.trace(f"loading conftestmodule {mod!r}") self.consider_conftest(mod, registration_name=conftestpath_plugin_name)