pytest-dev/pytest-cov
pytest-dev/pytest-cov has 2,076 GitHub stars and 256 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-07 23:14 UTC. Last push 2026-10-18.
Coverage plugin for pytest.
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original======== Overview
.. list-table:: :stub-columns: 1
* - docs
- |docs|
* - tests
- |github-actions|
* - package
- |version| |conda-forge| |wheel| |supported-versions| |supported-implementations| |commits-since|
.. |docs| image:: https://readthedocs.org/projects/pytest-cov/badge/?style=flat :target: https://readthedocs.org/projects/pytest-cov/ :alt: Documentation Status
.. |github-actions| image:: https://github.com/pytest-dev/pytest-cov/actions/workflows/test.yml/badge.svg :alt: GitHub Actions Status :target: https://github.com/pytest-dev/pytest-cov/actions
.. |version| image:: https://img.shields.io/pypi/v/pytest-cov.svg :alt: PyPI Package latest release :target: https://pypi.org/project/pytest-cov
.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pytest-cov.svg :target: https://anaconda.org/conda-forge/pytest-cov .. |wheel| image:: https://img.shields.io/pypi/wheel/pytest-cov.svg :alt: PyPI Wheel :target: https://pypi.org/project/pytest-cov
.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/pytest-cov.svg :alt: Supported versions :target: https://pypi.org/project/pytest-cov
.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/pytest-cov.svg :alt: Supported implementations :target: https://pypi.org/project/pytest-cov
.. |commits-since| image:: https://img.shields.io/github/commits-since/pytest-dev/pytest-cov/v7.1.0.svg :alt: Commits since latest release :target: https://github.com/pytest-dev/pytest-cov/compare/v7.1.0...master
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=testto 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 pytestyou 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
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.0may leave apytest-cov.pthif you installed without wheels (easy_install,setup.py installetc).pytest-cov 1.8 or olderwill leave ainit_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.
Explore related projects
affaan-m/ECC
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
299,311 starsNousResearch/hermes-agent
The agent that grows with you
261,573 starsmultica-ai/andrej-karpathy-skills
A single CLAUDE.md file to improve Claude Code behavior, derived from Andrej Karpathy's observations on LLM coding pitfalls.
230,692 starsfirecrawl/firecrawl
Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
199,551 stars