coveragepy

The industry-standard code coverage tool for measuring which lines and branches your Python tests actually execute.

Tool
PyPI
v7.16.0
3,410stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
93/100Excellent
Development Activity100
Maintenance100
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture90
Code Quality95
Innovation85
Learning Curve70

Coverage.py is the tool almost every Python testing setup runs underneath the hood, whether directly or via wrappers like pytest-cov and tox. It instruments a test run to record which lines and branches of your code actually executed, then turns that raw trace data into HTML, XML, JSON, and LCOV reports that highlight exactly what your test suite is missing.

Under the hood it can drive three different measurement engines depending on the Python version and what’s installed: a C extension tracer for speed, Python’s built-in sys.monitoring (PEP 669) on 3.12+ for near-zero overhead, or a pure-Python tracer as a portable fallback. A plugin system lets other tools (Cython, templating engines, Django’s template layer) report coverage for non-Python source, and a dynamic-contexts feature can attribute coverage to specific test cases or scenarios rather than just “was this line hit at all.”

What You Get

  • Line and branch coverage measurement across an entire test run, combinable across parallel processes and subprocesses
  • Multiple report formats out of the box: terminal summary, annotated HTML, XML (Cobertura-compatible), JSON, and LCOV
  • A SQLite-backed data store (.coverage) that supports combining data from distributed or parallel test runs
  • Pragma-based exclusion (# pragma: no cover) and configurable include/omit rules for controlling exactly what gets measured
  • Dynamic contexts to attribute coverage to specific tests, and a plugin API so non-Python file types can report their own coverage

Common Use Cases

  • Running coverage run -m pytest in CI to fail a build when coverage drops below a threshold
  • Generating an HTML coverage report to visually inspect exactly which lines a PR’s tests do and don’t exercise
  • Combining coverage data from parallelized or multi-process test suites with coverage combine
  • Feeding Cobertura/LCOV output into external tools like Codecov, Coveralls, or IDE coverage gutters

Under The Hood

Architecture The codebase is cleanly layered around a Control/Coverage facade (coverage/control.py) that wires together a Collector (coverage/collector.py), which owns per-thread Tracer instances, and a Core abstraction (coverage/core.py) that decides at runtime whether to use the C extension tracer, Python 3.12+‘s sys.monitoring backend (coverage/sysmon.py), or the pure-Python fallback tracer (coverage/pytracer.py) — the same public API works regardless of which engine is active underneath. Reporting is similarly decoupled: report_core.py provides a shared rendering pipeline that report.py, html.py, xmlreport.py, jsonreport.py, and lcovreport.py each plug into for their own output format, and sqldata.py/sqlitedb.py isolate all persistence behind a typed data-access layer so the on-disk .coverage schema can evolve without touching collection or reporting code. A plugin_support.py module defines a formal extension point for third-party file-type plugins (e.g. Cython, Django templates), keeping non-Python coverage support out of the core.

Tech Stack Coverage.py is implemented as a Python package with an optional C extension (coverage/ctracer/, built via setuptools) for the fast tracing path, falling back cleanly to pure Python where the extension isn’t available. It uses sqlite3 for its on-disk data store, supports both INI-style .coveragerc and pyproject.toml/tox.ini configuration via tomlconfig.py, and ships a sysmon.py module that adopts CPython’s PEP 669 sys.monitoring API on 3.12+. Development tooling is Ruff for formatting, mypy in strict mode for type checking, pytest with pytest-xdist for parallelized testing, and tox for cross-version test matrices; CI runs across GitHub Actions workflows for the test suite, quality checks, CodeQL scanning, dependency review, and PyPI publishing.

Code Quality The project is fully type-annotated and enforces mypy strict mode (disallow_untyped_defs, disallow_any_generics, warn_unreachable, and more), with Ruff configured for consistent formatting. Its own test suite is extensive — dozens of test modules under tests/, run with pytest-xdist across worker groups, including golden-file comparison tests (tests/gold/) and property-based tests via Hypothesis (tests/hypo.py). Fittingly, the project dogfoods its own tool: a dedicated metacov.ini configuration measures coverage of coverage.py’s own test suite. Naming and structure are consistent throughout, docstrings cover public modules and classes, and CodeQL plus a dependency-review workflow run on every change.

API Design The public surface is small and consistent: a single coverage.Coverage() object exposes start()/stop()/save() methods usable directly or as a context manager, with .coveragerc/pyproject.toml configuration covering the common cases so most projects never touch the API at all and just run the coverage CLI. Advanced features — dynamic contexts, per-file include/omit patterns, and the file-reporter plugin interface for non-Python sources — are opt-in layers on top of that simple default, keeping the barrier to entry low while still supporting complex multi-language, multi-process setups. The adoption of sys.monitoring for near-zero-overhead tracing on modern Python is a genuinely leading-edge integration few tools have implemented this thoroughly.

Used by 5 apps in this directory

Python
50%
Other

Airbyte

Developer Tools · Data Engineering

21,998

Open-source ELT platform with 600+ connectors for moving data from any source to warehouses, lakes, and AI agents.

View details
95
Repo Health
80
Technical
66
Dependency
Built with
Python50%
Kotlin41%
Updated today
Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,755

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python90%
Updated yesterday
TypeScript
92%
Other

GitNexus

Developer Tools · AI Code Assistants

47,086

Index any codebase into an interactive knowledge graph and give your AI agents deep architectural context via MCP — with zero servers required.

View details
88
Repo Health
86
Technical
73
Dependency
Built with
TypeScript92%
Updated yesterday
Python
64%
Other

Keep

Devops · Automation · Monitoring

12,290

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
91
Repo Health
79
Technical
66
Dependency
Built with
Python64%
TypeScript36%
Updated yesterday
C
76%
AGPL 3.0

TDengine

Databases

25,101

A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.

View details
99
Repo Health
71
Technical
68
Dependency
Built with
C76%
C++16%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search