Skip to content

Commit 7ffb269

Browse files
committed
Add test coverage collecting
I believe that we should be able to see the test coverage. These changes: - make tests use pytest - add displaying of the test coverage - add sending of collected coverage data to https://codecov.io
1 parent 9fa92f3 commit 7ffb269

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[run]
2+
omit =
3+
*/tests/*
4+
*/setup.py

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ venv*/
2525
pip-log.txt
2626

2727
# Unit test / coverage reports
28+
coverage.xml
2829
.coverage
2930
.nox
3031
.tox

coverage.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function cov {
6+
pytest "${1}/tests" \
7+
--cov opentelemetry-api \
8+
--cov opentelemetry-sdk \
9+
--cov ext \
10+
--cov examples \
11+
--cov-append \
12+
--cov-branch \
13+
--cov-report=
14+
}
15+
16+
17+
coverage erase
18+
19+
cov opentelemetry-api
20+
cov opentelemetry-sdk
21+
cov ext/opentelemetry-ext-http-requests
22+
cov ext/opentelemetry-ext-jaeger
23+
cov ext/opentelemetry-ext-wsgi
24+
cov examples/opentelemetry-example-app
25+
26+
coverage report
27+
coverage xml
28+
29+
codecov -v

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = -rs -v

tox.ini

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ skip_missing_interpreters = True
44
envlist =
55
py3{4,5,6,7,8}-test-{api,sdk,example-app,ext-wsgi,ext-http-requests,ext-jaeger}
66
pypy3-test-{api,sdk,example-app,ext-wsgi,ext-http-requests,ext-jaeger}
7+
py3{4,5,6,7,8}-coverage
8+
pypy3-coverage
79
lint
810
py37-{mypy,mypyinstalled}
911
docs
@@ -14,6 +16,9 @@ python =
1416

1517
[testenv]
1618
deps =
19+
test: pytest
20+
coverage: pytest-cov
21+
coverage: codecov
1722
mypy,mypyinstalled: mypy~=0.711
1823

1924
setenv =
@@ -42,12 +47,23 @@ commands_pre =
4247
jaeger: pip install {toxinidir}/opentelemetry-sdk
4348
jaeger: pip install {toxinidir}/ext/opentelemetry-ext-jaeger
4449

50+
; In order to get a healthy coverage report,
51+
; we have to install packages in editable mode.
52+
coverage: pip install -e {toxinidir}/opentelemetry-api
53+
coverage: pip install -e {toxinidir}/opentelemetry-sdk
54+
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-azure-monitor
55+
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-http-requests
56+
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-jaeger
57+
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-wsgi
58+
coverage: pip install -e {toxinidir}/examples/opentelemetry-example-app
59+
4560
; Using file:// here because otherwise tox invokes just "pip install
4661
; opentelemetry-api", leading to an error
4762
mypyinstalled: pip install file://{toxinidir}/opentelemetry-api/
4863

4964
commands =
50-
test: python -m unittest discover
65+
test: pytest
66+
coverage: {toxinidir}/coverage.sh
5167

5268
mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/
5369
; For test code, we don't want to enforce the full mypy strictness

0 commit comments

Comments
 (0)