This plugin provides a clean minimal set of command line options that are added to pytest. For further control of coverage use a coverage config file.
For example if tests are contained within the directory tree being measured the tests may be excluded if desired by using a .coveragerc file with the omit option set:
pytest --cov-config=.coveragerc --cov=myproj myproj/tests/
Where the .coveragerc file contains file globs:
[run] omit = tests/*
For full details refer to the coverage config file documentation.
This plugin overrides the
parallel options of coverage. Unless you also run coverage without
pytest-cov it’s pointless to set those options in your
If you use the
--cov=something option (with a value) then coverage’s
source option will also get overriden.
If you have multiple sources it might be easier to set those in
.coveragerc and always use
--cov (wihout a value)
instead of having a long command line with
--cov=pkg1 --cov=pkg2 --cov=pkg3 ....
If you use the
--cov-branch option then coverage’s
branch option will also get overriden.
If you wish to always add pytest-cov with pytest, you can use
[tool:pytest] addopts = --cov=<project-name> --cov-report html
A unfortunate consequence of coverage.py’s history is that
.coveragerc is a magic name: it’s the default file but it also
means “try to also lookup coverage configuration in
In practical terms this means that if you have your coverage configuration in
setup.cfg it is paramount
that you also use
You might not be affected but it’s unlikely that you won’t ever use
chdir in a test.
The complete list of command line options is:
Measure coverage for filesystem path. (multi-allowed)
Type of report to generate: term, term-missing, annotate, html, xml (multi-allowed). term, term- missing may be followed by “:skip-covered”. annotate, html and xml may be followed by “:DEST” where DEST specifies the output location. Use –cov-report= to not generate any output.
Config file for coverage. Default: .coveragerc
Do not report coverage if test run fails. Default: False
Disable coverage report completely (useful for debuggers). Default: False
Fail if the total coverage is less than MIN.
Do not delete coverage but append to current. Default: False
Enable branch coverage.
Choose the method for setting the dynamic context.