Skip to content

Code coverage

Configure coverage by editing .coveragerc:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[run]
branch = True

# coverage data file path
data_file = output/.coverage

# omitted file patterns
omit = mylib/tests/*, mylib/tools/*

[html]
# html report output folder
directory = output/htmlcov

Use pytest to measure coverage for mylib package:

1
coverage run --source=mylib -m pytest tests/

To generate html report:

1
coverage html

View output/htmlcov/index.html in browser.

Done.