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 <amotoki@gmail.com>
Change-Id: I106cb5227ca8c4f0a6f9d81c37e745a6f304de45
This commit is contained in:
Jim Rollenhagen 2020-08-11 15:53:42 -04:00 committed by Akihiro Motoki
parent 79e505520f
commit 1202faa709
3 changed files with 23 additions and 9 deletions

2
.gitignore vendored
View File

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

View File

@ -1,3 +1,12 @@
# Usage: unit_tests.sh [--coverage] <root_dir> [<test-file>, ...]
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 $?
}

View File

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