Registry / testing / coverage

coverage

JSON →
library7.15.4pypypi✓ verified 26d ago

Coverage.py is a tool for measuring code coverage of Python programs, currently at version 7.13.5, released on March 17, 2026. It is actively maintained with regular updates addressing various issues and enhancements.

pip install coverage
INSTALL
IMPORT
SIG · COVERAGE
C
coverage
testingpythonv7.15.4
Install
2.4s avg
Import
296ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.15.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.312s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.280s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Coverage
from coverage import Coverage
Ensure correct import path to access the Coverage class

Basic usage of Coverage.py to measure code coverage and generate an HTML report.

import os from coverage import Coverage # Start coverage measurement cov = Coverage() cov.start() # Your code to test # ... # Stop coverage measurement cov.stop() # Generate HTML report cov.html_report(directory=os.environ.get('COVERAGE_REPORT_DIR', 'covhtml'))
coverage --version
Debug
Known issues
breakingIn version 7.11.1, conflicts between a requested measurement core and other settings raised an error, which was a breaking change from previous behavior. This has been restored in version 7.11.3 to use another core instead and issue a warning.
fix
Upgrade to version 7.11.3 or later to restore previous behavior.
affects: 7.11.1
gotchaWhen using the 'sysmon' measurement core in version 7.11.1, a 'NotPython' exception could be raised if Python code was claimed to come from a non-Python file, such as Jinja templates compiled to Python. This issue has been fixed in version 7.11.2.
fix
Upgrade to version 7.11.2 or later to resolve this issue.
affects: 7.11.1
breakingThe 'coverage' library failed with a 'NoDataError' during report generation because no data was collected. This typically happens when the code intended for coverage measurement is not executed or when coverage data files are not properly saved or loaded in the current environment.
fix
Ensure that the target code is executed when coverage is active and that data collection and saving are configured correctly. Verify the execution environment and paths. Consult the 'coverage.py' documentation on 'No data collected' for detailed troubleshooting.
affects: coverage:7.10.7
gotchaThe `coverage.exceptions.NoDataError: No data to report.` occurs when no Python code is executed or recorded by the Coverage.py tool, leading to no coverage data being collected. This is often preceded by a `CoverageWarning: No data was collected. (no-data-collected)` message.
fix
Ensure that Python code intended for coverage measurement is executed under `coverage.py`'s control (e.g., using `coverage run <your_script.py>`) and that coverage data is saved before attempting to report it (e.g., `coverage combine`, `coverage html`). Verify that the executed script actually runs the relevant code.
affects: 7.13.5
Errors
Common errors & fixes
Coverage.py warning: No data was collected. (no-data-collected)
Coverage.py ran the program but did not measure any lines as executed, often due to incorrect `--source`, `--include`, or `--omit` configurations, or the code not actually being imported/run within the scope of measurement.
fix
Review your `coverage run` command and configuration file (`.coveragerc`): ensure `--source` or `[run] source` correctly points to the directories containing your code, add `__init__.py` files to your directories if they are Python packages, and check for conflicts where other tools might be overriding `sys.settrace`.
ModuleNotFoundError: No module named 'your_module'
When `coverage run` executes your script, it might be using a different Python interpreter or environment where the necessary modules are not installed or are not discoverable in `sys.path`.
fix
Run coverage using `python -m coverage run` to ensure it uses the same Python interpreter and its associated environment as your regular script execution. Additionally, ensure your project's root or relevant paths are correctly added to `PYTHONPATH` or specified via `coverage run --source`.
No data to report.
This often occurs after running tests in parallel (e.g., with `pytest-xdist`) where each process saves its coverage data to a separate file, and these files have not been combined before generating the report.
fix
After running `coverage run` with `parallel=True` (or similar parallel execution setup), you need to combine the individual `.coverage.*` data files into a single `.coverage` file using `coverage combine` before running `coverage report` or `coverage html`.
No source for code: 'filename.py'
Coverage.py traced a source file during execution but could not find the file when attempting to generate a report, often because the file was temporary and deleted, or located outside the configured source/include paths.
fix
Adjust the `[run] source` setting in `.coveragerc` to prevent measurement of code outside your project. Alternatively, use `[report] omit` to explicitly skip reporting on temporary directories (e.g., `omit=$TMPDIR/*`), or set `[report] ignore_errors = true` to treat the error as a warning.
Upgrade
Version history
7.15.4latest on PyPI · released Aug 6, 2026
Audit
Dependencies
pytestoptionalCommonly used for running tests in conjunction with Coverage.py
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources