Python Coverage Measurement — ELI5

Imagine you’re checking a house before moving in. You walk through the kitchen, the living room, maybe peek into the bathroom. But if you skip the basement, you might miss a leaky pipe that floods everything later.

Coverage measurement does the same thing for your code. It watches which lines of code actually run when your tests execute and tells you which lines were never touched.

Say you wrote a program with 100 lines. Your tests run, and coverage reports that 72 lines were exercised. That’s 72% coverage. The remaining 28 lines? Nobody tested them. They might work fine, or they might contain a bug waiting to strike.

Coverage doesn’t tell you if your tests are good — just that they ran certain code. A test could run a line and check nothing useful. But knowing which code is completely untested is still valuable information. It’s the difference between “we might have checked that” and “we definitely never checked that.”

Teams use coverage to find blind spots. When a bug appears in untested code, nobody is surprised. When every line has been exercised at least once, you sleep a little better at night.

One thing to remember: Coverage tells you where your tests haven’t gone, not whether they checked anything meaningful once they got there.

pythontestingquality

See Also