coverage
Code coverage measurement for Python — tracks which lines and branches of code are executed during tests. coverage features: coverage run for executing code with measurement, coverage report for terminal summary, coverage html for interactive HTML report, coverage xml for CI integration (Codecov, SonarQube), branch coverage (branch=True), partial branch detection, .coveragerc / pyproject.toml configuration, omit= and include= for file filtering, coverage combine for merging multiple runs, coverage erase, plugins for Django/Flask, context labels for test-specific coverage, and pytest-cov for pytest integration.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Code coverage tool. No network calls in core. coverage html generates local HTML — no external assets. .coverage database file contains code paths — not sensitive but should not be committed to git (add to .gitignore). XML reports sent to Codecov/Coveralls expose code structure — use private repos or self-hosted coverage services for proprietary code.
⚡ Reliability
Best When
Measuring test completeness and finding untested code — coverage.py is the universal Python coverage tool used in virtually every Python CI/CD pipeline.
Avoid When
Mutation testing (use mutmut), performance profiling (use cProfile/py-spy), or production runtime coverage monitoring.
Use Cases
- • Agent run with coverage — coverage run -m pytest tests/; coverage report — run tests; agent measures coverage during test run; report shows line-by-line percentages; --fail-under=80 exits non-zero if below 80% coverage threshold
- • Agent HTML report — coverage run -m pytest; coverage html; open htmlcov/index.html — visual report; agent generates interactive HTML showing which lines are covered (green) or missed (red); htmlcov/index.html is the entry point; useful for finding untested code
- • Agent branch coverage — coverage run --branch -m pytest; coverage report — branch; agent tracks conditional branches (if/else, try/except); shows partial branch misses where one branch taken but not other; more accurate than line coverage alone
- • Agent pytest integration — pytest --cov=src --cov-report=term-missing --cov-report=html --cov-fail-under=80 — pytest-cov; agent integrates coverage into pytest run; --cov= specifies which directories to measure; term-missing shows missing line numbers; single command for test + coverage
- • Agent CI coverage — coverage xml -o coverage.xml; bash <(curl -s https://codecov.io/bash) — Codecov; agent generates XML report for CI/CD services; coverage.xml follows Cobertura format; used by Codecov, Coveralls, SonarQube
Not For
- • Mutation testing — coverage shows which lines run, not whether tests are meaningful; for mutation testing use mutmut or cosmic-ray
- • Performance profiling — coverage adds overhead; for performance use cProfile or py-spy
- • Production monitoring — coverage.py is for development; for production code coverage use dd-trace or elastic APM
Interface
Authentication
No auth — local code coverage tool.
Pricing
coverage.py is Apache 2.0 licensed. Created by Ned Batchelder. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ source= required for accurate measurement — coverage run without source= may miss unimported modules; agent code: coverage run --source=src/mypackage -m pytest — measures only specified package; without source=, unimported modules show 0% but not in report; omit= for excluding test files from measurement
- ⚠ Branch coverage requires --branch flag — coverage run -m pytest without --branch measures only line coverage; missing branch coverage misses if/else arms and short-circuit evaluation; agent code: always use --branch: coverage run --branch; or in .coveragerc: [run]; branch = True
- ⚠ # pragma: no cover for intentional exclusions — coverage: if TYPE_CHECKING: ... # pragma: no cover — skips block; single line: x = 1 # pragma: no cover; agent code: use sparingly for genuinely unreachable code, debug-only code, or platform-specific branches; don't use to inflate coverage numbers
- ⚠ Coverage data file is .coverage (hidden) — coverage run creates .coverage in current directory; coverage html reads .coverage; agent code: run coverage commands from project root; CI: ensure .coverage file is preserved between coverage run and coverage report steps; use --data-file= to specify location
- ⚠ Parallel test runs need combine — pytest-xdist parallel tests create separate .coverage.* files; coverage combine merges them; agent code with -n auto: add --cov-config=.coveragerc with [run] parallel = True; or: coverage combine after parallel test run; without combine, only one worker's coverage counted
- ⚠ omit= paths are relative to source root — omit=['*/tests/*', '*/migrations/*'] in .coveragerc; paths are glob patterns relative to file being measured; agent code: test that omit patterns work: coverage report --show-missing and verify test files are omitted; absolute paths not recommended — use relative globs
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for coverage.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.