Skip to content

Commit

Permalink
Add test coverage collecting
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jamim committed Oct 9, 2019
1 parent 9fa92f3 commit 7ffb269
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
*/tests/*
*/setup.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ venv*/
pip-log.txt

# Unit test / coverage reports
coverage.xml
.coverage
.nox
.tox
Expand Down
29 changes: 29 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -e

function cov {
pytest "${1}/tests" \
--cov opentelemetry-api \
--cov opentelemetry-sdk \
--cov ext \
--cov examples \
--cov-append \
--cov-branch \
--cov-report=
}


coverage erase

cov opentelemetry-api
cov opentelemetry-sdk
cov ext/opentelemetry-ext-http-requests
cov ext/opentelemetry-ext-jaeger
cov ext/opentelemetry-ext-wsgi
cov examples/opentelemetry-example-app

coverage report
coverage xml

codecov -v
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = -rs -v
18 changes: 17 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ skip_missing_interpreters = True
envlist =
py3{4,5,6,7,8}-test-{api,sdk,example-app,ext-wsgi,ext-http-requests,ext-jaeger}
pypy3-test-{api,sdk,example-app,ext-wsgi,ext-http-requests,ext-jaeger}
py3{4,5,6,7,8}-coverage
pypy3-coverage
lint
py37-{mypy,mypyinstalled}
docs
Expand All @@ -14,6 +16,9 @@ python =

[testenv]
deps =
test: pytest
coverage: pytest-cov
coverage: codecov
mypy,mypyinstalled: mypy~=0.711

setenv =
Expand Down Expand Up @@ -42,12 +47,23 @@ commands_pre =
jaeger: pip install {toxinidir}/opentelemetry-sdk
jaeger: pip install {toxinidir}/ext/opentelemetry-ext-jaeger

; In order to get a healthy coverage report,
; we have to install packages in editable mode.
coverage: pip install -e {toxinidir}/opentelemetry-api
coverage: pip install -e {toxinidir}/opentelemetry-sdk
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-azure-monitor
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-http-requests
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-jaeger
coverage: pip install -e {toxinidir}/ext/opentelemetry-ext-wsgi
coverage: pip install -e {toxinidir}/examples/opentelemetry-example-app

; Using file:// here because otherwise tox invokes just "pip install
; opentelemetry-api", leading to an error
mypyinstalled: pip install file://{toxinidir}/opentelemetry-api/

commands =
test: python -m unittest discover
test: pytest
coverage: {toxinidir}/coverage.sh

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

0 comments on commit 7ffb269

Please sign in to comment.