Use pytest-cov plugin for getting coverage

Change-Id: Ifb5db0e8b1e12cf7d14045c2ccc7fc5ebfeaa40b
This commit is contained in:
Federico Ressi 2021-01-27 13:22:48 +01:00
parent db64a23d0d
commit 190451d1ed
4 changed files with 14 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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} "

12
tox.ini
View File

@ -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