Need help with pytest-cov?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

996 Stars 139 Forks MIT License 799 Commits 98 Opened issues


Coverage plugin for pytest.

Services available


Need anything else?

Contributors list



.. start-badges

.. list-table:: :stub-columns: 1

* - docs
  - |docs|
* - tests
  - | |travis| |appveyor| |requires|
* - package
  - | |version| |conda-forge| |wheel| |supported-versions| |supported-implementations|
    | |commits-since|

.. |docs| image:: :target: :alt: Documentation Status

.. |travis| image:: :alt: Travis-CI Build Status :target:

.. |appveyor| image:: :alt: AppVeyor Build Status :target:

.. |requires| image:: :alt: Requirements Status :target:

.. |version| image:: :alt: PyPI Package latest release :target:

.. |conda-forge| image:: :target:

.. |commits-since| image:: :alt: Commits since latest release :target:

.. |wheel| image:: :alt: PyPI Wheel :target:

.. |supported-versions| image:: :alt: Supported versions :target:

.. |supported-implementations| image:: :alt: Supported implementations :target:

.. end-badges

This plugin produces coverage reports. Compared to just using

coverage run
this plugin does some extras:
  • Subprocess support: you can fork or run stuff in a subprocess and will get covered without any fuss.
  • Xdist support: you can use all of pytest-xdist's features and still get coverage.
  • Consistent pytest behavior. If you run
    coverage run -m pytest
    you will have slightly different
    (CWD will be in it, unlike when running

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

Upgrading from ancient pytest-cov

pytest-cov 2.0
is using a new
file (
). You may want to manually remove the older
from site-packages as it's not automatically removed.


Uninstall with pip::

pip uninstall pytest-cov

Under certain scenarios a stray

file may be left around in site-packages.
  • pytest-cov 2.0
    may leave a
    if you installed without wheels (
    , install
  • pytest-cov 1.8 or older
    will leave a



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%


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

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.

For subprocess measurement environment variables must make it from the main process to the subprocess. The python used by the subprocess must have pytest-cov installed. The subprocess must do normal site initialisation so that the environment variables can be detected and coverage started.


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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.