Coverage.py: Code Coverage Measurement for Python
raw JSON → 7.13.5 verified Tue May 12 auth: no python install: verified quickstart: stale
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 Common errors
error Coverage.py warning: No data was collected. (no-data-collected) ↓
cause 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. error ModuleNotFoundError: No module named 'your_module' ↓
cause 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. error No data to report. ↓
cause 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. error No source for code: 'filename.py' ↓
cause 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. Warnings
breaking In 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.
gotcha When 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.
breaking The '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.
gotcha The `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.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.24s 19.2M
3.10 slim (glibc) - - 0.16s 20M
3.11 alpine (musl) - - 0.50s 21.3M
3.11 slim (glibc) - - 0.29s 22M
3.12 alpine (musl) - - 0.33s 13.1M
3.12 slim (glibc) - - 0.30s 14M
3.13 alpine (musl) - - 0.33s 12.8M
3.13 slim (glibc) - - 0.28s 13M
3.9 alpine (musl) - - 0.23s 18.7M
3.9 slim (glibc) - - 0.20s 19M
Imports
- Coverage
from coverage import Coverage
Quickstart stale last tested: 2026-04-23
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'))