Ensuring code coverage in unit testing?

reckoner picture reckoner · Jul 23, 2010 · Viewed 17.4k times · Source

I have noticed that even though I have a lot of doctests in our Python code, when I trace the testing using the methods described here:

traceit

I find that there are certain lines of code that are never executed. I currently sift through the traceit logs to identify blocks of code that are never run, and then try to come up with different test cases to exercise these particular blocks. As you can imagine, this is very time-consuming and I was wondering if we are going about this the wrong way and whether you all have other advice or suggestions to deal with this problem, which I'm sure must be common as software becomes sufficiently complex.

Answer

Hank Gay picture Hank Gay · Jul 23, 2010

coverage.py is a very handy tool. Among other things, it provides branch coverage.