pytest-dev/pytest-cov — 2.1k★ on GitHub (Python). Coverage plugin for pytest.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
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 different sys.path (CWD will be
in it, unlike when running pytest).
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
Installation
Install with pip::
pip install pytest-cov
For distributed testing support install pytest-xdist::
pip install pytest-xdist
Migrating from coverage.py
coverage run -m pytest and pytest --cov do not necessarily import code the same way. The former starts pytest with
python -m, which adds the current working directory to sys.path. The latter uses the pytest command, which does
not add it automatically. If coverage drops unexpectedly after switching, check that the package under test is installed
in your environment (for example, with pip install -e .) rather than relying on the working directory being importable.
Run pytest --cov=myproj tests/ from the same environment to confirm that tests still import your package.
For subprocess coverage, pytest-cov 7 no longer installs the .pth file used by earlier releases; see
Upgrading from pytest-cov 6.3_ below for the replacement.
Upgrading from pytest-cov 6.3
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 <https://coverage.readthedocs.io/en/latest/config.html#run-patch>_ to enable subprocess measurements.
Uninstalling
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.
Usage
::
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%
Documentation
https://pytest-cov.readthedocs.io/en/latest/
Coverage Data File
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.
Limitations
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.
Security
To report a security vulnerability please use the Tidelift security contact <https://tidelift.com/security>_.
Tidelift will coordinate the fix and disclosure.
Acknowledgements
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.
How active is development on pytest-dev/pytest-cov?
The most recent commit recorded on pytest-dev/pytest-cov was 1 month ago, based on the GitHub push timestamp. The repository has 259 forks — one of the better signals of community interest.
How does pytest-dev/pytest-cov compare to other Backend projects?
pytest-dev/pytest-cov is tracked by TopGit in the Backend category, with 2.1k GitHub stars and written in Python. Browse the Backend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does pytest-dev/pytest-cov have?
pytest-dev/pytest-cov has 2.1k GitHub stars — refresh the page for the live number, or check github.com/pytest-dev/pytest-cov. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What is pytest-dev/pytest-cov?
pytest-dev/pytest-cov (pytest-dev/pytest-cov) is a Python project on GitHub. From the project's own README: Coverage plugin for pytest.
What language is pytest-dev/pytest-cov written in?
pytest-dev/pytest-cov is written primarily in Python. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is pytest-dev/pytest-cov associated with?
GitHub's repository topics for pytest-dev/pytest-cov: "pytest", "python". TopGit's editorial category is Backend.
Why is pytest-dev/pytest-cov categorized under Backend?
TopGit places pytest-dev/pytest-cov in the Backend category based on its GitHub topics and description (tagged: "pytest", "python"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Is pytest-cov worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of pytest-cov.