"Tell" coverage to track subprocesses.

This commit is contained in:
Pedro Algarvio 2019-01-25 12:58:52 +00:00
parent f27589aff7
commit 39fb981faa
No known key found for this signature in database
GPG Key ID: BB36BF6584A298FF
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
'''
Python will always try to import sitecustomize.
We use that fact to try and support code coverage for sub-processes
'''
from __future__ import absolute_import
try:
import coverage
coverage.process_startup()
except ImportError:
pass

25
tox.ini
View File

@ -29,6 +29,12 @@ commands = {envpython} {toxinidir}/tests/runtests.py --tests-logfile={toxinidir}
commands = pytest --rootdir {toxinidir} --log-file={toxinidir}/artifacts/logs/runtests.log {posargs}
[testenv:runtests-coverage]
# Add tests/support/coverage to PYTHONPATH in order to get code coverage from subprocesses.
# Additional, set the COVERAGE_PROCESS_START environment variable so that the coverage library
# knows it's supposed to track subprocesses.
setenv =
PYTHONPATH={toxinidir}/tests/support/coverage
COVERAGE_PROCESS_START={toxinidir}/.coveragerc
commands_pre =
- coverage erase
commands =
@ -38,6 +44,7 @@ commands_post =
- coverage xml -o {toxinidir}/artifacts/coverage/coverage.xml
[testenv:pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands = coverage run -m py.test --rootdir {toxinidir} {posargs}
commands_post = {[testenv:runtests-coverage]commands_post}
@ -51,17 +58,20 @@ commands = {[testenv:runtests]commands}
[testenv:py2-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py2-runtests-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py2-pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:pytest-coverage]commands}
commands_pre = {[testenv:pytest-coverage]commands_pre}
commands_post = {[testenv:pytest-coverage]commands_post}
@ -75,17 +85,20 @@ commands = {[testenv:runtests]commands}
[testenv:py27-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py27-runtests-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py27-pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:pytest-coverage]commands}
commands_pre = {[testenv:pytest-coverage]commands_pre}
commands_post = {[testenv:pytest-coverage]commands_post}
@ -99,17 +112,20 @@ commands = {[testenv:runtests]commands}
[testenv:py3-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py3-runtests-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py3-pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:pytest-coverage]commands}
commands_pre = {[testenv:pytest-coverage]commands_pre}
commands_post = {[testenv:pytest-coverage]commands_post}
@ -124,17 +140,20 @@ commands = {[testenv:runtests]commands}
[testenv:py34-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py34-runtests-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py34-pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:pytest-coverage]commands}
commands_pre = {[testenv:pytest-coverage]commands_pre}
commands_post = {[testenv:pytest-coverage]commands_post}
@ -149,17 +168,20 @@ commands = {[testenv:runtests]commands}
[testenv:py35-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py35-runtests-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py35-pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:pytest-coverage]commands}
commands_pre = {[testenv:pytest-coverage]commands_pre}
commands_post = {[testenv:pytest-coverage]commands_post}
@ -174,17 +196,20 @@ commands = {[testenv:runtests]commands}
[testenv:py36-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py36-runtests-coverage]
deps = {[testenv:runtests]deps}
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:runtests-coverage]commands}
commands_pre = {[testenv:runtests-coverage]commands_pre}
commands_post = {[testenv:runtests-coverage]commands_post}
[testenv:py36-pytest-coverage]
setenv = {[testenv:runtests-coverage]setenv}
commands = {[testenv:pytest-coverage]commands}
commands_pre = {[testenv:pytest-coverage]commands_pre}
commands_post = {[testenv:pytest-coverage]commands_post}