From 190451d1edfbca1503e964acd004d73ca645ab9b Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 27 Jan 2021 13:22:48 +0100 Subject: [PATCH] Use pytest-cov plugin for getting coverage Change-Id: Ifb5db0e8b1e12cf7d14045c2ccc7fc5ebfeaa40b --- extra-requirements.txt | 3 +++ test-requirements.txt | 3 +-- tools/run_tests.py | 13 +++++-------- tox.ini | 12 +++++------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/extra-requirements.txt b/extra-requirements.txt index 248e84500..067e40cf3 100644 --- a/extra-requirements.txt +++ b/extra-requirements.txt @@ -1,6 +1,9 @@ +# Additional requirements not in openstack/requirements project + ansi2html # LGPLv3+ pandas # BSD podman # Apache-2.0 +pytest-cov # MIT pytest-rerunfailures # MPL-2.0 pytest-timeout # MIT validations-libs # APACHE-2.0 diff --git a/test-requirements.txt b/test-requirements.txt index 60d17c430..8d570f462 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,5 @@ -# Unit tests requirements +# Test cases requirements -coverage>=5.3.1 # Apache-2.0 mock>=3.0.5 # BSD psutil>=5.8.0 # BSD pytest>=6.2.1 # MIT diff --git a/tools/run_tests.py b/tools/run_tests.py index 734df9225..606100305 100755 --- a/tools/run_tests.py +++ b/tools/run_tests.py @@ -54,10 +54,7 @@ TOX_RUN_TESTS_TIMEOUT = float(os.environ.get('TOX_RUN_TESTS_TIMEOUT') or 0.) TOX_RERUNS = int(os.environ.get('TOX_RERUNS') or 0) TOX_RERUNS_DELAY = int(os.environ.get('TOX_RERUNS_DELAY') or 5) - -TOX_PYDEV_DEBUG = bool( - os.environ.get('TOX_PYDEV_DEBUG', 'false').lower() in - ['true', 'yes', '1']) +TOX_COVER = bool(os.environ.get('TOX_COVER', 'false').lower() in ['1', 'yes', 'true']) def main(): @@ -81,10 +78,6 @@ def run_tests(): cleanup_report_dir() log_environ() - if TOX_PYDEV_DEBUG: - debug_test_cases() - return True - succeeded = True try: run_test_cases() @@ -144,9 +137,13 @@ def run_test_cases(): rerun_options = '' if TOX_RERUNS: rerun_options = f"--reruns '{TOX_RERUNS}' --reruns-delay '{TOX_RERUNS_DELAY}'" + cover_options = '' + if TOX_COVER: + cover_options = f"--cov=tobiko" common.execute(f"pytest " f"{xdist_options} " f"{rerun_options} " + f"{cover_options} " f"--log-file={TOX_REPORT_LOG} " f"--junitxml={TOX_REPORT_XML} " f"--junit-prefix={TOX_REPORT_NAME} " diff --git a/tox.ini b/tox.ini index 0c1242057..ca0cce8d1 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,8 @@ setenv = PYTHONWARNINGS = ignore::Warning,{env:PYTHONWARNINGS:} RUN_TESTS_EXTRA_ARGS = {env:OS_TEST_PATH} TOBIKO_PREVENT_CREATE = {env:TOBIKO_PREVENT_CREATE:false} + TOX_COVER = {env:TOX_COVER:false} + TOX_COVER_DIR = {env:TOX_COVER_DIR:{toxinidir}/cover} TOX_NUM_PROCESSES = {env:TOX_NUM_PROCESSES:auto} TOX_REPORT_NAME = {env:TOX_REPORT_NAME:tobiko_results_{envname}} TOX_REPORT_DIR = {env:TOX_REPORT_DIR:{envlogdir}} @@ -54,17 +56,13 @@ basepython = {[testenv:py3]basepython} envdir = {[testenv:py3]envdir} setenv = {[testenv]setenv} - PYTHON = coverage run --parallel-mode + TOX_COVER = true TOX_COVER_DIR={env:TOX_COVER_DIR:{toxinidir}/cover} + commands = - find . -type f -name ".coverage.*" -delete - coverage erase {[testenv]commands} - coverage combine coverage html -d "{env:TOX_COVER_DIR}" - coverage xml -o "{env:TOX_COVER_DIR}/cover/coverage.xml" - coverage report --skip-covered - find . -type f -name ".coverage.*" -delete + coverage xml -o "{env:TOX_COVER_DIR}/coverage.xml" whitelist_externals = find