From dc0cfc8ec9c9b30cc9d358eb33bd6c401140bdb8 Mon Sep 17 00:00:00 2001 From: Paul Goins Date: Fri, 1 Mar 2019 10:11:49 +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: I253e35de7ba72fb2f6a3ad018a45924771443465 --- .zuul.yaml | 1 + tox.ini | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/.zuul.yaml b/.zuul.yaml index 5e75d94..387b944 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,3 +2,4 @@ templates: - python-charm-jobs - openstack-python35-jobs + - openstack-cover-jobs diff --git a/tox.ini b/tox.ini index fdbdc66..40eca15 100644 --- a/tox.ini +++ b/tox.ini @@ -52,6 +52,33 @@ basepython = python3.5 deps = -r{toxinidir}/test-requirements.txt commands = flake8 {posargs} src unit_tests +[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/* + [testenv:venv] basepython = python3 commands = {posargs}