17

I'm using coverage.py to measure the code coverage of my tests. I've enabled branch coverage, but I can't quite make sense of the report.

Without branch coverage, I get 100% coverage:

Name                           Stmts   Miss  Cover   Missing
------------------------------------------------------------
mylib/queries.py                  44      0   100%

With branch coverage enabled:

Name                           Stmts   Miss Branch BrPart  Cover   Missing
--------------------------------------------------------------------------
mylib/queries.py                  44      1     20      3    94%   55, 21->10, 53->-48, 59->-58

The source in question can be found here.

21->10 makes sense; the if clause never evaluates to False (jumping back to the beginning of the outer for loop).

However, 53->-48 and 59->-58 have me scratching my head. What do they mean?

David Eyk
  • 12,171
  • 11
  • 63
  • 103
  • It's probably an empty list inside of that for loop so it never executes the code inside the loop. – Dan May 18 '16 at 15:37
  • 1
    Hm, yeah, the loops always have something to chew on in the test cases I'm providing. So the missing "branch" is the case of an empty set? – David Eyk May 18 '16 at 15:46

1 Answers1

19

Dan's comment is close. First, the negative numbers mean, an exit from a function starting at that line number. So -48 means, exit from the function starting at line 48.

The issue isn't empty loops: those branches would have happened if the loops ever completed. It looks like perhaps they did not.

BTW: Coverage.py 4.1b3 has changed some of this behavior: they'd be marked as 53->exit, 59->exit. Also, the branches themselves might be identified differently. Give it a try.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • Ned, thanks for taking the time to answer my question, and thanks for this truly useful package. – David Eyk May 19 '16 at 04:38
  • The output in 4.1b3 definitely makes more sense, however I'm still confused by `53->exit`; line 53 here is [a for-loop inside a generator function](https://gist.github.com/eykd/1d9cbb50f1cae0873bac05e3a20909ea#file-queries-py-L53) and not really a branch. What am I missing? – David Eyk May 19 '16 at 04:50
  • Your for-loop never finishes, so it never naturally exits the function. I'm not sure what it does do, though. Perhaps an exception? – Ned Batchelder May 19 '16 at 11:04
  • I see. That gives me enough to go on. Thanks again. – David Eyk May 19 '16 at 14:17