[TIP] How do I get coverage on the test modules themselves?

Ben Finney ben+python at benfinney.id.au
Mon Sep 15 19:16:18 PDT 2014


"Mcgregor, Cecil" <cmcgregor at paypal.com> writes:

> I'm using coverage 3.7.1 with python 2.7.3 on Red Hat 4.1.2 linux
>
> I've been attempting to get coverage on the test code themselves.

Test coverage refers to coverage of the system under test. That
necessarily excludes the test code.

If you want to have test coverage *of* any code, you have to test that
code. The tests themselves aren't tested in this process, and the
reporting tool is correct to exclude them from the coverage report.

> How do I cover the test_*.py files as part of the coverage reports?

You'll need to design tests which test *that* code, and run them. This
is, as you might gather, a recursive loop which can go on indefinitely.

You need to decide where to stop it, by picking the tests which are not
themselves tested — and which therefore are correctly excluded from the
test coverage report.

So the test code should:

* not be counted since you're not testing it, and therefore
* be as simple and clear as possible to minimise possible bugs.

-- 
 \     “On the other hand, you have different fingers.” —Steven Wright |
  `\                                                                   |
_o__)                                                                  |
Ben Finney




More information about the testing-in-python mailing list