[elbe-devel] [PATCH] elbevalidate: pytest: don't import real python modules through MainModule

Thomas Weißschuh thomas.weissschuh at linutronix.de
Thu Aug 22 10:20:35 CEST 2024


The special MainModule handling is meant for modules which are not
recognized by pytest by default as such, because they are missing the
.py extensions.
When used with a file that is recognized by pytest as module, then this
file will be collected twice.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbevalidate/pytest.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/elbevalidate/pytest.py b/elbevalidate/pytest.py
index b287c8aa60b5..344dc9bf8424 100644
--- a/elbevalidate/pytest.py
+++ b/elbevalidate/pytest.py
@@ -22,7 +22,7 @@ class _ElbeValidationPlugin:
         self.test_script = test_script
 
     def pytest_collect_file(self, file_path, parent):
-        if os.fspath(file_path) == os.fspath(self.test_script):
+        if not file_path.suffix == '.py' and os.fspath(file_path) == os.fspath(self.test_script):
             return _MainModule.from_parent(parent, path=file_path)
 
     @pytest.hookimpl

---
base-commit: f6a64a263fbfbb5c89fa39e741899bf461a11195
change-id: 20240822-elbevalidate-duplicate-detection-0b4aef7e9b30

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list