Skip to content

Commit 63cfd4d

Browse files
committed
Add new script to combine the coverage data of several versions (for Python 2/3 only codepaths)
1 parent 1bedd86 commit 63cfd4d

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
/+junk
1717

1818
# Build artefacts
19-
build/
20-
dist/
19+
/coverage/
20+
/build/
21+
/dist/
2122

2223
# Documentation build artefacts
2324
docs/build/

test/combine-coverage.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/python
2+
import glob
3+
import os
4+
import pathlib
5+
6+
import coverage
7+
8+
# Monkey-patch `coverage` to not randomly delete files
9+
import coverage.data
10+
coverage.data.file_be_gone = lambda *a: None
11+
12+
# Switch working directory to project directory
13+
BASE_PATH = pathlib.Path(__file__).parent.parent
14+
DATA_PATH = BASE_PATH / "coverage"
15+
os.chdir(str(BASE_PATH))
16+
17+
18+
cov = coverage.Coverage()
19+
20+
# Load the most recent coverage data collected for each test platform
21+
cov.combine(glob.glob("build/test-py*/cov_raw"), strict=True)
22+
23+
cov.report()
24+
cov.html_report(directory=str(DATA_PATH / "cov_html"))
25+
cov.xml_report(outfile=str(DATA_PATH / "cov.xml"))

test/run-tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def _contextlib_suppress(*exceptions):
126126
"--cov-report=xml:{}".format(str(TEST_PATH / "cov.xml"))
127127
] + sys.argv[1:])
128128
finally:
129+
# Move coverage file to test directory (so that the coverage files of different
130+
# versions can be merged later on)
131+
shutil.move(str(BASE_PATH / ".coverage"), str(TEST_PATH / "cov_raw"))
132+
129133
# Make sure daemon was terminated during the tests
130134
if DAEMON.poll() is None: # "if DAEMON is running"
131135
DAEMON.kill()

tox.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ deps =
2727
commands =
2828
flake8 {posargs}
2929

30+
[testenv:coverage]
31+
basepython = python3
32+
deps =
33+
coverage
34+
commands =
35+
python "{toxinidir}/test/combine-coverage.py" {posargs}
36+
3037
[flake8]
31-
exclude = .git,.tox,+junk,dist,doc,*egg,build,tools,test/unit,docs,*__init__.py
38+
exclude = .git,.tox,+junk,coverage,dist,doc,*egg,build,tools,test/unit,docs,*__init__.py
3239

3340
# E221: Multiple spaces before operator
3441
# E241: Multiple spaces after ',': Breaks element alignment collections

0 commit comments

Comments
 (0)