Glossary

Coverage

Code coverage is a measure of how much of your source code is executed during testing. The primary tool for measuring coverage in Python is coverage.py (installed via pip install coverage), which tracks which lines, branches, and functions are executed and produces reports showing what is tested and what is not. The pytest-cov plugin integrates coverage measurement directly into pytest.

The most common metric is line coverage — the percentage of source lines executed at least once during the test suite. Branch coverage is stricter: it checks that every branch of every conditional (both the if and else paths) has been exercised. Coverage reports can be generated as text, HTML (with line-by-line highlighting), XML (for CI integration), or JSON.

Coverage is a useful guide but not a guarantee of quality. 100% line coverage does not mean your code is bug-free — it means every line was executed, not that every behaviour was verified. Conversely, untested code is a clear risk. A practical target for most projects is 80–90% coverage, with critical paths (security, financial calculations) tested more rigorously. Coverage reports are most valuable for identifying untested code paths you were not aware of.

Related terms: pytest, Fixture

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.