From: Sebastian Wagner Date: Sun, 20 Jun 2021 09:45:52 +0000 (+0200) Subject: qa: convert test_import.py to pytest X-Git-Tag: v17.1.0~1352^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ddfb5eb8386201105d5890260507663b7eed50da;p=ceph.git qa: convert test_import.py to pytest Signed-off-by: Sebastian Wagner --- diff --git a/qa/CMakeLists.txt b/qa/CMakeLists.txt index a72f9088408a..884c41e4bbaf 100644 --- a/qa/CMakeLists.txt +++ b/qa/CMakeLists.txt @@ -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() diff --git a/qa/test_import.py b/qa/test_import.py index fe70a1c49805..4ee59b565092 100644 --- a/qa/test_import.py +++ b/qa/test_import.py @@ -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) diff --git a/qa/tox.ini b/qa/tox.ini index b5e4b2a647a4..1046597ac166 100644 --- a/qa/tox.ini +++ b/qa/tox.ini @@ -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 +