API Reference
Coverage.py
A tool for measuring code coverage of Python programs, with branch analysis and HTML reports.
Official Documentation ↗CompatibilityThis documentation covers version
v7.4. Check the official docs for the latest API surface.Installation
pip
pip install coverageMethods
No methods match this filter.
Coverage.py traces execution, records which lines and branches ran, and renders reports.
Key Features
- Line and branch coverage
- Multiple report formats
- Combines data from parallel runs
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The official API reference declares the following error types:
coverage.exceptions.CoverageException(class(所有异常的基类)) — official text: “class coverage.exceptions. CoverageException” (source: https://coverage.readthedocs.io/en/latest/api_exceptions.html, fetched 2026-11-08T17:26:00+08:00)coverage.exceptions.ConfigError(exception) — official text: “A problem with a config file, or a value in one.” (source: https://coverage.readthedocs.io/en/latest/api_exceptions.html, fetched 2026-11-08T17:26:00+08:00)coverage.exceptions.DataError(exception) — official text: “An error in using a data file.” (source: https://coverage.readthedocs.io/en/latest/api_exceptions.html, fetched 2026-11-08T17:26:00+08:00)coverage.exceptions.NoDataError(exception) — official text: “We didn’t have data to work with.” (source: https://coverage.readthedocs.io/en/latest/api_exceptions.html, fetched 2026-11-08T17:26:00+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T17:26:00+08:00 via WebFetch https://coverage.readthedocs.io/en/latest/api_coverage.html;WebFetch https://coverage.readthedocs.io/en/latest/cmd.html;WebFetch https://coverage.readthedocs.io/en/latest/api_exceptions.html.
coverage run→ signature from https://coverage.readthedocs.io/en/latest/cmd.html; official text: “Usage: coverage run [options][program options]” coverage.Coverage→ signature from https://coverage.readthedocs.io/en/latest/api_coverage.html; official text: “class coverage.Coverage(data_file=MISSING, data_suffix=None, cover_pylib=None, auto_data=False, timid=None, branch=None, config_file=True, source=None, source_pkgs=None, source_dirs=None, omit=None,”
FAQ
- How do I enable branch coverage?
- Run with --branch or set branch = true in the config so partial branch execution is counted as missing.
- Why is my subprocess not covered?
- Coverage does not trace child processes by default; set concurrency or use coverage run on the child as well.
- How do I fail CI below a threshold?
- Use --fail-under with coverage report so the command exits non-zero when coverage is below the limit.
Report a problem with this API docOpens a pre-filled issue on GitHub.