Running coverage on your tests

Wednesday 15 June 2011

Here’s a true story from the #python IRC channel, a frequently-asked question played out for real. I’m nedbat, the other nick has been changed to protect the innocent:

other: there’s no way to automagically omit coveraging the actual test modules is there?

nedbat: you can add an omit line to the .coveragerc, but I’ve found useful info from coverage on my tests.

other: What kind of useful info?

nedbat: useful info: two test methods with the same name (by accident) so one was never called.

other: hah oh boy, one of the test modules I was ignoring sure enough was a test that wasn’t being run :). Perhaps I better not, I hadn’t thought of that before.

nedbat: yay coverage! :)

other: yay coverage!

Moral of the story: if you have enough tests to run coverage, then your tests are a serious part of your product. You should run coverage on them, it will help.


It's also useful for test suites that don't have automatic test discovery (e.g. Python's own regrtest): if you add a test, but forget to add the incantation to invoke it, it will show up in your test coverage data.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.