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 b7dea94
Show file tree
Hide file tree
Showing 6 changed files with 54 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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ install:

script:
- tox

after_success:
- pip install codecov
- codecov -v
27 changes: 27 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/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
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
17 changes: 16 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,8 @@ python =

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

setenv =
Expand Down Expand Up @@ -42,12 +46,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 b7dea94

Please sign in to comment.