]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa: convert test_import.py to pytest
authorSebastian Wagner <sewagner@redhat.com>
Sun, 20 Jun 2021 09:45:52 +0000 (11:45 +0200)
committerSebastian Wagner <sewagner@redhat.com>
Fri, 2 Jul 2021 08:35:19 +0000 (10:35 +0200)
Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
qa/CMakeLists.txt
qa/test_import.py
qa/tox.ini

index a72f9088408ac8c39fdbbc26168f33185c44c0fb..884c41e4bbafe376ccc7d952901749440aba72ca 100644 (file)
@@ -5,5 +5,5 @@ endif()
 
 if(WITH_TESTS)
   include(AddCephTest)
-  add_tox_test(qa TOX_ENVS py3 flake8 import-tasks mypy)
+  add_tox_test(qa TOX_ENVS py3 flake8 mypy)
 endif()
index fe70a1c49805d748489fe47c057f2fbc36a2629d..4ee59b565092576187a3966c5ef9083cf85bebdb 100644 (file)
@@ -1,11 +1,10 @@
 # try to import all .py files from a given directory
 
-import argparse
 import glob
 import os
 import importlib
 import importlib.util
-
+import pytest
 
 def _module_name(path):
     task = os.path.splitext(path)[0]
@@ -19,25 +18,21 @@ def _import_file(path):
     line = f'Importing {package}{mod_name} from {path}'
     print(f'{line:<80}', end='')
     mod_spec = importlib.util.find_spec(mod_name, package)
-    mod = mod_spec.loader.load_module()
+    mod = mod_spec.loader.load_module(f'{package}{mod_name}')
     if mod is None:
         result = 'FAIL'
     else:
         result = 'DONE'
     print(f'{result:>6}')
     mod_spec.loader.exec_module(mod)
+    return result
 
-def _parser():
-    parser = argparse.ArgumentParser(
-        description='Try to import a file',
-        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-    parser.add_argument('path', nargs='+', help='Glob to select files')
-    return parser
+def get_paths():
+    for g in ['tasks/**/*.py']:
+        for p in glob.glob(g, recursive=True):
+            yield p
 
+@pytest.mark.parametrize("path", list(sorted(get_paths())))
+def test_import(path):
+    assert _import_file(path) == 'DONE'
 
-if __name__ == '__main__':
-    parser = _parser()
-    args = parser.parse_args()
-    for g in args.path:
-        for p in glob.glob(g, recursive=True):
-            _import_file(p)
index b5e4b2a647a46284a8652e2f1d45b3004010b597..1046597ac1661f1b18a3cb38bad594f522b19ae7 100644 (file)
@@ -22,14 +22,12 @@ deps =
   -c{toxinidir}/../src/mypy-constrains.txt
 commands = mypy {posargs:.}
 
-[testenv:import-tasks]
-basepython = python3
-deps = {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[coverage,orchestra,test]
-commands = python test_import.py {posargs:tasks/**/*.py}
-
 [testenv:py3]
 basepython = python3
 deps =
-  {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[test]
+  {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[coverage,orchestra,test]
   httplib2
-commands = pytest -vv tasks/tests
+commands =
+  pytest --assert=plain test_import.py
+  pytest tasks/tests
+