Library / SDK
coveragepy/coveragepy avatar
coveragepy/coveragepy

Coverage.py 7.16: Python Coverage Measurement with Standard Library Tracing

The code coverage tool for Python. It uses the code analysis tools and tracing hooks provided in the Python standard library to determine which lines are executable, and which have been executed.

3,412 stars523 forksPythonApache-2.0

At a glance

What is it?
Coverage.py measures which lines of Python code execute during tests, using only standard library tracing hooks. This review covers its mechanism, setup, limitations, and alternatives for engineers deciding whether to adopt it.
Who is it for?
Adopt Coverage.py if you need reliable line coverage for Python 3.10 through 3.15, including free-threading and PyPy3, and you want a tool that integrates with pytest, unittest, or Django. Do not choose it if you need branch or mutation coverage, or if you require support for Python versions older than 3.10.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What Coverage.py Solves and Who Needs It

Coverage.py answers a simple question: which lines of your Python code actually ran during a test session? This is the foundation of test quality assessment. It targets Python developers and teams who use continuous integration and want to identify untested branches or dead code. The tool is not a test framework itself; it integrates with your existing test runner. The README states it 'measures code coverage, typically during test execution.' This is for anyone who needs a standard, widely adopted coverage tool that works across CPython and PyPy, including the newer free-threading builds.

Mechanism: Standard Library Tracing Hooks

Coverage.py does not instrument your code by rewriting it. Instead, it uses the code analysis tools and tracing hooks provided in the Python standard library. Specifically, it relies on the `sys.settrace` and `sys.setprofile` mechanisms to observe line execution. The README explicitly says it uses 'the code analysis tools and tracing hooks provided in the Python standard library.' This means it does not require a compiler or a separate runtime. The tracing hook fires on each line execution, and Coverage.py records which lines were hit. It also uses the `ast` module to determine which lines are executable, distinguishing between lines that can run and lines that are purely decorative. This design keeps the tool lightweight and portable across Python implementations, but it also means the tracing overhead can be significant for large codebases.

Getting Started: Commands and Configuration

The README points to a Quick Start section in the docs for running coverage on a test suite. The typical workflow, as described in the official documentation (not reproduced here), is to install with `pip install coverage`, then run `coverage run -m pytest` or `coverage run -m unittest`. After tests finish, you generate a report with `coverage report` or `coverage html`. The tool supports configuration via a `.coveragerc` file or `pyproject.toml` under the `[tool.coverage]` section, where you can set `source`, `omit`, and `include` patterns. The README does not list these commands, but it links to the Quick Start for details. For a project that uses pytest, the command is straightforward: `coverage run -m pytest && coverage report`. This produces a text summary of coverage percentages per module.

Supported Python Versions and Free-Threading

Coverage.py runs on Python 3.10 through 3.15 rc1, including free-threading builds, and PyPy3 versions 3.10 and 3.11. This is a broad support range, but it also sets a hard floor: if you are stuck on Python 3.9 or earlier, this tool will not work. The free-threading support is notable because it means Coverage.py can handle the new no-GIL mode in Python 3.13 and later. However, the README does not detail how tracing behaves under free-threading, so you should verify that your specific threading model produces accurate results. The project's recent releases (7.16.0 in August 2026) show active maintenance, but the README does not specify which Python versions are deprecated over time, so check the changelog for breaking changes.

Limitations: Line Coverage Only and Overhead

Coverage.py measures line coverage, not branch coverage. The README says it determines 'which lines are executable, and which have been executed.' This means it will not tell you if both sides of an `if` statement were taken. For that, you need a different tool. Additionally, the tracing hook approach imposes a runtime overhead on every executed line. In large test suites, this can slow down execution noticeably. The README does not quantify the overhead, but it is a known trade-off of using Python's tracing API. Another limitation: code that uses `exec` or `eval` with dynamically generated source may not be captured accurately because the tracing hooks may not see the generated code as part of the original module. If your codebase relies on such patterns, you need to test Coverage.py's behavior with your specific cases.

Alternatives and How They Differ

The primary alternative is `pytest-cov`, which is a wrapper around Coverage.py for pytest users. It provides a simpler command-line interface (`pytest --cov=myproject`) and integrates coverage reporting into pytest's output. The difference is that pytest-cov is a plugin that drives Coverage.py, so you still get the same underlying measurement mechanism. If you want branch coverage, you might consider `coverage` with the `branch` option enabled, but Coverage.py's branch support is not mentioned in the README. Another alternative is `trace`, a standard library module that also uses tracing hooks but with a more limited reporting format. The key difference is that Coverage.py offers richer output formats (HTML, XML, JSON) and configuration options, while `trace` is minimal. For mutation testing, you would look at `mutmut`, which changes the source code and runs tests again, a fundamentally different approach.

Maintenance and License Implications

Coverage.py is licensed under Apache-2.0, which permits commercial use, modification, and distribution without copyleft obligations. The README includes a NOTICE.txt file for attribution details. The project is actively maintained, with releases 7.15.3, 7.15.4, and 7.16.0 occurring within a month in 2026. The last push date is 2026-08-28, indicating ongoing development. The README mentions a Tidelift subscription for enterprise support, which is a commercial option but not required. For maintenance cost, you should expect to update the tool regularly to keep up with Python releases. The project has a code of conduct and contributing guidelines, suggesting a community-driven process. There is no explicit statement about long-term support for older Python versions, so you should plan to upgrade Coverage.py when you upgrade Python.

Editorial conclusion

Adopt Coverage.py if you need reliable line coverage for Python 3.10 through 3.15, including free-threading and PyPy3, and you want a tool that integrates with pytest, unittest, or Django. Do not choose it if you need branch or mutation coverage, or if you require support for Python versions older than 3.10. Before adopting, verify that your test runner and CI environment can handle the tracing overhead, and confirm that your codebase's dynamic patterns (like exec or eval) are measured accurately. Coverage.py's Apache-2.0 license and active maintenance (releases in 2026) make it a safe default, but its line-focused approach means you must pair it with other tools for deeper quality gates.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Community notes

Community notes