Skip to content

Commit 9f25fb3

Browse files
committed
Be able to run coverage on all toxenvs.
Shifts coverage into an optional CLI wrapper that's dropped in only when enabled via an environment variable. This means any toxenv can now be wrapped into a coverage run by running e.g. `tox -e py38-format-coverage` instead of `tox -e py38-format-tests`. Credits to @nedbat and @The-Compiler.
1 parent a951fc7 commit 9f25fb3

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020
- name: Install tox
2121
run: python -m pip install tox
2222
- name: Collect & Upload Coverage
23-
run: python -m tox -e codecov
23+
run: python -m tox -e pypy3-format-coverage
2424
env:
2525
CODECOV_TOKEN: 2b38dae1-41c4-4435-a29d-79a1299e5617

tox.ini

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@ skipsdist = True
1010

1111
[testenv]
1212
changedir = {envtmpdir}
13+
passenv = CODECOV* CI
1314
setenv =
1415
JSON_SCHEMA_TEST_SUITE = {toxinidir}/json
16+
17+
coverage,codecov: MAYBE_COVERAGE = coverage run -m
18+
coverage,codecov: COVERAGE_RCFILE={toxinidir}/.coveragerc
19+
coverage,codecov: COVERAGE_DEBUG_FILE={envtmpdir}/coverage-debug
20+
coverage,codecov: COVERAGE_FILE={envtmpdir}/coverage-data
1521
whitelist_externals =
1622
mkdir
1723
commands =
1824
noextra: {envpython} -m pip install {toxinidir}
1925
format: {envpython} -m pip install '{toxinidir}[format]'
2026
format_nongpl: {envpython} -m pip install '{toxinidir}[format_nongpl]'
2127

22-
tests: {envpython} -m twisted.trial {posargs:jsonschema}
28+
tests,coverage: {envpython} -m {env:MAYBE_COVERAGE:} twisted.trial {posargs:jsonschema}
2329
tests: {envpython} -m doctest {toxinidir}/README.rst
2430

31+
coverage: {envpython} -m coverage report --show-missing
32+
coverage: {envpython} -m coverage html --directory={envtmpdir}/htmlcov
33+
codecov: {envpython} -m coverage xml -o {envtmpdir}/coverage.xml
34+
codecov: codecov --required --disable gcov --file {envtmpdir}/coverage.xml
35+
2536
perf: mkdir {envtmpdir}/benchmarks/
2637
perf: {envpython} {toxinidir}/jsonschema/benchmarks/issue232.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/issue232.json
2738
perf: {envpython} {toxinidir}/jsonschema/benchmarks/json_schema_test_suite.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/json_schema_test_suite.json
@@ -69,17 +80,6 @@ deps =
6980
commands =
7081
{envpython} -m flake8 {posargs} {toxinidir}/jsonschema {toxinidir}/docs
7182

72-
[testenv:coverage]
73-
setenv =
74-
{[testenv]setenv}
75-
COVERAGE_DEBUG_FILE={envtmpdir}/coverage-debug
76-
COVERAGE_FILE={envtmpdir}/coverage-data
77-
commands =
78-
{envpython} -m pip install '{toxinidir}[format]'
79-
{envpython} -m coverage run --rcfile={toxinidir}/.coveragerc -m twisted.trial jsonschema
80-
{envpython} -m coverage report --rcfile={toxinidir}/.coveragerc --show-missing
81-
{envpython} -m coverage html --directory={envtmpdir}/htmlcov --rcfile={toxinidir}/.coveragerc {posargs}
82-
8383
[testenv:docs-html]
8484
basepython = pypy3
8585
commands = {envpython} -m sphinx -b html {toxinidir}/docs/ {envtmpdir}/build {posargs:-a -n -q -T -W}
@@ -115,12 +115,3 @@ deps =
115115
doc8
116116
pygments
117117
pygments-github-lexers
118-
119-
[testenv:codecov]
120-
passenv = CODECOV* CI
121-
setenv = {[testenv:coverage]setenv}
122-
commands =
123-
{envpython} -m pip install '{toxinidir}[format]'
124-
{envpython} -m coverage run --rcfile={toxinidir}/.coveragerc -m twisted.trial jsonschema
125-
{envpython} -m coverage xml -o {envtmpdir}/coverage.xml
126-
codecov --required --disable gcov --file {envtmpdir}/coverage.xml

0 commit comments

Comments
 (0)