From 1c71b1c9693ea87e18a9fefaa8287e892c11139b Mon Sep 17 00:00:00 2001 From: Paul Goins Date: Fri, 1 Mar 2019 11:25:26 +0100 Subject: [PATCH] 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: Ia32b6c0b2ff61a2775e34b2958982f0ae11cdd8d --- .coveragerc | 7 ------- .zuul.yaml | 1 + tox.ini | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index e580a736..00000000 --- a/.coveragerc +++ /dev/null @@ -1,7 +0,0 @@ -[report] -# Regexes for lines to exclude from consideration -exclude_lines = - if __name__ == .__main__.: -include= - hooks/glance_* - actions/actions.py diff --git a/.zuul.yaml b/.zuul.yaml index 7051aeeb..dc276615 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,3 +1,4 @@ - project: templates: - python35-charm-jobs + - openstack-cover-jobs diff --git a/tox.ini b/tox.ini index 387ea9a9..f608acc3 100644 --- a/tox.ini +++ b/tox.ini @@ -40,6 +40,34 @@ deps = -r{toxinidir}/requirements.txt commands = flake8 {posargs} hooks unit_tests tests actions lib 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] basepython = python3 commands = {posargs}