]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Test all module imports
authorZack Cerza <zack@redhat.com>
Mon, 20 Mar 2023 19:28:48 +0000 (13:28 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 20 Mar 2023 19:33:49 +0000 (13:33 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/test/test_imports.py [new file with mode: 0644]

diff --git a/teuthology/test/test_imports.py b/teuthology/test/test_imports.py
new file mode 100644 (file)
index 0000000..b73ade1
--- /dev/null
@@ -0,0 +1,29 @@
+import pytest
+
+from pathlib import Path
+from subprocess import check_call
+from typing import List
+
+root = Path("./teuthology")
+
+
+def find_modules() -> List[str]:
+    modules = []
+    for path in root.rglob("*.py"):
+        if path.name.startswith("test_"):
+            continue
+        if "-" in path.name:
+            continue
+        if path.name == "__init__.py":
+            path = path.parent
+
+        path_name = str(path).replace("/", ".")
+        if path_name.endswith(".py"):
+            path_name = path_name[:-3]
+        modules.append(path_name)
+    return sorted(modules)
+
+
+@pytest.mark.parametrize("module", find_modules())
+def test_import_modules(module):
+    check_call(["python3", "-c", f"import {module}"])