How to Install pytest-cov in Python
Pytest plugin for measuring coverage.
pip install pytest-cov
What is pytest-cov?
Pytest plugin for measuring coverage.
- docs - |docs| - tests - |github-actions| - package - |version| |conda-forge| |wheel| |supported-versions| |supported-implementations| |commits-since|
This plugin provides coverage functionality as a pytest plugin. Compared to just using `` this plugin does some extras:
Automatic erasing and combination of .coverage files and default reporting. Support for detailed coverage contexts (add `` 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 `` (CWD will be in it, unlike when running ``).
Quick Start
Minimal example to get started with pytest-cov:
import pytest_cov
print(pytest_cov.__version__)
Installation
pip (standard)
pip install pytest-cov
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install pytest-cov
pip3
pip3 install pytest-cov
conda
conda install -c conda-forge pytest-cov
Poetry
poetry add pytest-cov
Dependencies
Installing pytest-cov will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import pytest_cov; print(pytest_cov.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing pytest-cov with pip.
ModuleNotFoundError: No module named 'pytest_cov'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install pytest-cov. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'pytest_cov' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install pytest-cov to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'pytest_cov'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show pytest-cov and upgrade with pip install --upgrade pytest-cov.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install pytest-cov. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user pytest-cov
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pytest-cov
Recent Releases
| Version | Released |
|---|---|
7.1.0 latest |
2026-03-21 |
7.0.0 |
2025-09-09 |
6.3.0 |
2025-09-06 |
6.2.1 |
2025-06-12 |
6.2.0 |
2025-06-11 |
Manage pytest-cov
Upgrade to latest version
pip install --upgrade pytest-cov
Install a specific version
pip install pytest-cov==7.1.0
Uninstall
pip uninstall pytest-cov
Check what is installed
pip show pytest-cov