From baf3ced0c32072a5fa525277380a8777fc0a471a Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 18 Jan 2017 15:07:46 +1100 Subject: [PATCH] Fix coverage report There's a few things going on here Firstly, we need to install coverage tool in test-requirements Secondly, .testr.conf has to use PYTHON because the coverage report works by resetting PYTHON='coverage run ...' Thirdly, because we call ourselves diskimage-builder but the python module is diskimage_builder that seems to confuse things. We need to use "setup.py test" (note, that is different to "setup.py testr"!) to use the PBR testr wrapper. That exposes a --coverage-package-name argument that calls the coverage tool with the right argument. With this I got a coverage report for our unit tests Change-Id: I9012e18eb7d01bee035140e70afa76c47c27eb01 --- .testr.conf | 2 +- test-requirements.txt | 2 ++ tox.ini | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.testr.conf b/.testr.conf index 25d7f8d9..d7b8b32f 100644 --- a/.testr.conf +++ b/.testr.conf @@ -4,7 +4,7 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ OS_DEBUG=${OS_DEBUG:-0} \ - python -m subunit.run discover . $LISTOPT $IDOPTION + ${PYTHON:-python} -m subunit.run discover . $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/test-requirements.txt b/test-requirements.txt index f9f2a6b8..a30316a7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -12,3 +12,5 @@ oslosphinx>=4.7.0 # Apache-2.0 # releasenotes reno>=1.8.0 # Apache-2.0 + +coverage>=4.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 4bd24a3f..fe0a09e2 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ install_command = pip install -U {opts} {packages} deps= -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands= - python setup.py testr --slowest --testr-args='{posargs}' + python setup.py test --slowest --testr-args='{posargs}' [testenv:pep8] commands = @@ -24,9 +24,10 @@ envdir = {toxworkdir}/venv commands = {toxinidir}/tests/run_functests.sh {posargs} [testenv:cover] -setenv = PYTHON=coverage run --source diskimage_builder -commands = bash -c 'if [ ! -d ./.testrepository ] ; then testr init ; fi' - bash -c 'testr run --parallel ; RET=$? ; coverage combine ; coverage html -d ./cover $OMIT && exit $RET' +# NOTE: this is "setup.py test" (*not* testr) which is a pbr wrapper +# around testr. This understands --coverage-package-name which we +# need due to underscore issues. +commands = python setup.py test --coverage --coverage-package-name diskimage_builder --testr-args='{posargs}' [testenv:docs] commands = python setup.py build_sphinx