From 1202faa70901588f91c7ab61e31fb8215c72445d Mon Sep 17 00:00:00 2001 From: Jim Rollenhagen Date: Tue, 11 Aug 2020 15:53:42 -0400 Subject: [PATCH] Fix coverage job `coverage run pytest` runs coverage against the tests in a file called "pytest", whereas `coverage run -m pytest` uses pytest as the test runner, which is what we really want here. To avoid duplicated maitenance of pytest arguments, unit_tests.sh is updated to handle the coverage run. Co-Authored-By: Akihiro Motoki Change-Id: I106cb5227ca8c4f0a6f9d81c37e745a6f304de45 --- .gitignore | 2 +- tools/unit_tests.sh | 21 +++++++++++++++++---- tox.ini | 9 +++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a810c24b96..b15111ab7a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ .DS_STORE .DS_Store /cover +/coverage/ coverage.xml coverage-karma pep8.txt @@ -19,7 +20,6 @@ pylint.txt RELEASENOTES.rst releasenotes/build releasenotes/notes/reno.cache -reports openstack_dashboard/local/* !openstack_dashboard/local/local_settings.py.example diff --git a/tools/unit_tests.sh b/tools/unit_tests.sh index 2a0374af76..45da9e9b1d 100755 --- a/tools/unit_tests.sh +++ b/tools/unit_tests.sh @@ -1,3 +1,12 @@ +# Usage: unit_tests.sh [--coverage] [, ...] + +if [ "$1" = "--coverage" ]; then + shift + coverage=1 +else + coverage=0 +fi + root=$1 posargs="${@:2}" @@ -52,11 +61,15 @@ function run_test { fi fi - report_args="--junitxml=$report_dir/${project}_test_results.xml" - report_args+=" --html=$report_dir/${project}_test_results.html" - report_args+=" --self-contained-html" + if [ "$coverage" -eq 1 ]; then + coverage run -m pytest $target --ds=$settings_module -m "$tag" + else + report_args="--junitxml=$report_dir/${project}_test_results.xml" + report_args+=" --html=$report_dir/${project}_test_results.html" + report_args+=" --self-contained-html" - pytest $target --ds=$settings_module -v -m "$tag" $report_args + pytest $target --ds=$settings_module -v -m "$tag" $report_args + fi return $? } diff --git a/tox.ini b/tox.ini index fb0fe98f53..0a88f7e974 100644 --- a/tox.ini +++ b/tox.ini @@ -49,13 +49,14 @@ commands = [testenv:cover] envdir = {toxworkdir}/venv +whitelist_externals = + bash commands = coverage erase - coverage run pytest horizon/test/ --ds=horizon.test.settings {posargs} - coverage run -a pytest openstack_dashboard --ds=openstack_dashboard.test.settings -m "not integration" {posargs} - coverage run -a pytest openstack_auth/tests --ds=openstack_auth.tests.settings {posargs} + bash {toxinidir}/tools/unit_tests.sh --coverage {toxinidir} coverage xml - coverage html + coverage html -d coverage + coverage report --show-missing --skip-covered [testenv:selenium] envdir = {toxworkdir}/venv