Added tox environment for gathering coverage

This technique was borrowed from the tox "cover" environment in
openstack/nova's tox.ini.  This leverages the fact that stestr lets
you override the python executable via the PYTHON environment
variable.  Doing this allows us to easily generate coverage for our
unit tests.

An important caveat is that this does not provide any coverage for
tests via zaza, amulet, etc.  It is purely focused on the unit tests.

Note that this replaces the previous .coveragerc; coverage
configuration is instead pulled from tox.ini.

Change-Id: Iadfc6d9775269a9ede7bd35c5c455342696ffce9
This commit is contained in:
Paul Goins 2019-03-01 11:12:24 +01:00
parent a39788cb95
commit 14507e4ea7
3 changed files with 29 additions and 6 deletions

View File

@ -1,6 +0,0 @@
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
if __name__ == .__main__.:
include=
hooks/cinder_*

View File

@ -1,3 +1,4 @@
- project: - project:
templates: templates:
- python35-charm-jobs - python35-charm-jobs
- openstack-cover-jobs

28
tox.ini
View File

@ -39,6 +39,34 @@ deps = -r{toxinidir}/requirements.txt
commands = flake8 {posargs} hooks unit_tests tests actions lib commands = flake8 {posargs} hooks unit_tests tests actions lib
charm-proof charm-proof
[testenv:cover]
# Technique based heavily upon
# https://github.com/openstack/nova/blob/master/tox.ini
basepython = python3
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
setenv =
{[testenv]setenv}
PYTHON=coverage run
commands =
coverage erase
ostestr {posargs}
coverage combine
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage report
[coverage:run]
branch = True
concurrency = multiprocessing
parallel = True
source =
.
omit =
.tox/*
*/charmhelpers/*
unit_tests/*
[testenv:venv] [testenv:venv]
basepython = python3 basepython = python3
commands = {posargs} commands = {posargs}