Testing & Quality Assurance

coverage

A highlighter that marks exactly which lines of your code your tests actually touched, and which you're flying blind on.

Install it: pip install coverage

What does it do?

Coverage.py runs alongside your test suite and tracks, line by line, which parts of your code actually got executed during testing. Afterward it produces a report, often color-coded green for tested and red for untested, showing exactly where the gaps are, the same way a highlighter shows which parts of a textbook you actually read versus skipped. It doesn’t tell you if your tests are good, only whether they exercised the code at all, which is a useful but limited signal.

See it in action

These are two commands typed in a terminal: the first runs your tests while secretly tracking which lines of code were actually used, and the second prints a report showing what was and wasn’t tested.

coverage run -m pytest
coverage report -m

Why would a non-developer care?

A team can have hundreds of tests and still have huge, completely untested sections of their actual product; coverage reports are how you find out you’ve been testing the easy parts while ignoring risky ones. It’s a reality check against the comfortable but sometimes false feeling that having tests means being fine.

Real-world examples

Coverage.py has been maintained for well over a decade and is deeply embedded in Python’s testing culture, often wired directly into continuous integration pipelines that block a code change from merging if test coverage drops below a set threshold. Teams that skip measuring coverage sometimes discover, only after a production incident, that the exact function that broke had zero tests around it the entire time.

Who uses it

Development teams who want to measure and enforce how thoroughly their automated tests actually exercise their codebase.

How it compares to alternatives

It’s less a competitor to pytest and more a companion; pytest-cov is a popular plugin that wires coverage.py directly into pytest’s test runs, and the two are frequently used together rather than as alternatives.

Fun fact

Coverage.py has been maintained by Ned Batchelder since 2004, making it one of the longest continuously maintained tools in the Python testing ecosystem.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries