Browse Source

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
changes/03/640303/2
Paul Goins 2 months ago
parent
commit
14507e4ea7
3 changed files with 29 additions and 6 deletions
  1. 0
    6
      .coveragerc
  2. 1
    0
      .zuul.yaml
  3. 28
    0
      tox.ini

+ 0
- 6
.coveragerc View File

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

+ 1
- 0
.zuul.yaml View File

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

+ 28
- 0
tox.ini View File

@@ -39,6 +39,34 @@ deps = -r{toxinidir}/requirements.txt
39 39
 commands = flake8 {posargs} hooks unit_tests tests actions lib
40 40
            charm-proof
41 41
 
42
+[testenv:cover]
43
+# Technique based heavily upon
44
+# https://github.com/openstack/nova/blob/master/tox.ini
45
+basepython = python3
46
+deps = -r{toxinidir}/requirements.txt
47
+       -r{toxinidir}/test-requirements.txt
48
+setenv =
49
+    {[testenv]setenv}
50
+    PYTHON=coverage run
51
+commands =
52
+    coverage erase
53
+    ostestr {posargs}
54
+    coverage combine
55
+    coverage html -d cover
56
+    coverage xml -o cover/coverage.xml
57
+    coverage report
58
+
59
+[coverage:run]
60
+branch = True
61
+concurrency = multiprocessing
62
+parallel = True
63
+source =
64
+    .
65
+omit =
66
+    .tox/*
67
+    */charmhelpers/*
68
+    unit_tests/*
69
+
42 70
 [testenv:venv]
43 71
 basepython = python3
44 72
 commands = {posargs}

Loading…
Cancel
Save