Coverage.py: Code Coverage Measurement for Python
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.
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.
- 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.
Install
-
pip install coverage
Imports
- Coverage
from coverage import Coverage
Quickstart
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'))