From 8593eaf9fbbb0a7fd7239d6db1a780a884705c7b Mon Sep 17 00:00:00 2001 From: Kenji Ishii Date: Mon, 12 Sep 2016 21:09:34 +0900 Subject: [PATCH] Enable test coverage in run_test.sh and tox About run_test.sh, the report of test coverage seems not create at the moment. Also tox for cover doesn't work well. This patch fix it. Change-Id: I408b4c053c4290c7a205d892c43cb7cd2bbff641 --- .gitignore | 3 +++ run_tests.sh | 8 ++++++-- tox.ini | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 59d7bf46..519fc685 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ magnum_ui/test/.secret_key_store *.lock *.egg* *.swp +.coverage +coverage.xml +htmlcov diff --git a/run_tests.sh b/run_tests.sh index 267fed31..f21e51ed 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -365,6 +365,10 @@ function run_tests_all { if [ "$NOSE_WITH_HTML_OUTPUT" = '1' ]; then export NOSE_HTML_OUT_FILE='dashboard_nose_results.html' fi + if [ $with_coverage -eq 1 ]; then + ${command_wrapper} python -m coverage.__main__ erase + coverage_run="python -m coverage.__main__ run -p" + fi ${command_wrapper} ${coverage_run} $root/manage.py test magnum_ui --settings=openstack_dashboard.test.settings $testopts # get results of the openstack_dashboard tests DASHBOARD_RESULT=$? @@ -372,8 +376,8 @@ function run_tests_all { if [ $with_coverage -eq 1 ]; then echo "Generating coverage reports" ${command_wrapper} python -m coverage.__main__ combine - ${command_wrapper} python -m coverage.__main__ xml -i --include="horizon/*,openstack_dashboard/*" --omit='/usr*,setup.py,*egg*,.venv/*' - ${command_wrapper} python -m coverage.__main__ html -i --include="horizon/*,openstack_dashboard/*" --omit='/usr*,setup.py,*egg*,.venv/*' -d reports + ${command_wrapper} python -m coverage.__main__ xml -i --include="magnum_ui/*" --omit='/usr*,setup.py,*egg*,.venv/*' + ${command_wrapper} python -m coverage.__main__ html -i --include="magnum_ui/*" --omit='/usr*,setup.py,*egg*,.venv/*' -d reports fi # Remove the leftover coverage files from the -p flag earlier. rm -f .coverage.* diff --git a/tox.ini b/tox.ini index 635df6f4..8c2cc0c5 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,11 @@ commands = flake8 {posargs} commands = {posargs} [testenv:cover] -commands = python setup.py test --coverage --testr-args='{posargs}' +commands = + coverage erase + coverage run {toxinidir}/manage.py test magnum_ui --settings=magnum_ui.test.settings {posargs} --exclude-dir=magnum_ui/test/integration_tests {posargs} + coverage xml --omit '.tox/cover/*' + coverage html --omit '.tox/cover/*' [testenv:py27dj18] basepython = python2.7