docs | |
---|---|
tests | |
package |
This plugin provides coverage functionality as a pytest plugin. Compared to just using coverage run
this plugin does some extras:
- Automatic erasing and combination of .coverage files and default reporting.
- Support for detailed coverage contexts (add
--cov-context=test
to have the full test name including parametrization as the context). - Xdist support: you can use all of pytest-xdist's features including remote interpreters and still get coverage.
- Consistent pytest behavior. If you run
coverage run -m pytest
you will have slightly differentsys.path
(CWD will be in it, unlike when runningpytest
).
All features offered by the coverage package should work, either through pytest-cov's command line options or through coverage's config file.
- Free software: MIT license
Install with pip:
pip install pytest-cov
For distributed testing support install pytest-xdist:
pip install pytest-xdist
pytest-cov 6.3 and older were using a .pth
file to enable coverage measurements in subprocesses. This was removed in pytest-cov 7 - use coverage's patch options to enable subprocess measurements.
Uninstall with pip:
pip uninstall pytest-cov
Under certain scenarios a stray .pth
file may be left around in site-packages.
- pytest-cov 2.0 may leave a
pytest-cov.pth
if you installed without wheels (easy_install
,setup.py install
etc). - pytest-cov 1.8 or older will leave a
init_cov_core.pth
.
pytest --cov=myproj tests/
Would produce a report like:
-------------------- coverage: ... --------------------- Name Stmts Miss Cover ---------------------------------------- myproj/__init__ 2 0 100% myproj/myproj 257 13 94% myproj/feature4286 94 7 92% ---------------------------------------- TOTAL 353 20 94%
https://pytest-cov.readthedocs.io/en/latest/
The data file is erased at the beginning of testing to ensure clean data for each test run. If you
need to combine the coverage of several test runs you can use the --cov-append
option to append
this coverage data to coverage data from previous test runs.
The data file is left at the end of testing so that it is possible to use normal coverage tools to examine it.
For distributed testing the workers must have the pytest-cov package installed. This is needed since the plugin must be registered through setuptools for pytest to start the plugin on the worker.
To report a security vulnerability please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
Whilst this plugin has been built fresh from the ground up it has been influenced by the work done on pytest-coverage (Ross Lawley, James Mills, Holger Krekel) and nose-cover (Jason Pellerin) which are other coverage plugins.
Ned Batchelder for coverage and its ability to combine the coverage results of parallel runs.
Holger Krekel for pytest with its distributed testing support.
Jason Pellerin for nose.
Michael Foord for unittest2.
No doubt others have contributed to these tools as well.