Issue #175 resolved

branch coverage gets confused in certain for loops

Ben Webb
created an issue

coverage gets the branch information wrong for the following (contrived) Python code:

{{{ o = [(1,2), (3,4)] for tup in [a for a in o if a[0] > 1]: x = tup[0] y = tup[1] print x,y

$ coverage run --branch test.py && coverage report && coverage html 3 4 Name Stmts Miss Branch BrPart Cover


test 5 0 4 2 78% }}}

The HTML output shows that the last line (print x,y) has two branches that were not taken (to exit, or to continue the loop). This is, of course, incorrect.

The following code is equivalent but is reported correctly as having no missing lines or branches:

{{{ o = [(1,2), (3,4)] o = [a for a in o if a[0] > 1] for tup in o: x = tup[0] y = tup[1] print x,y

$ coverage run --branch test.py && coverage report && coverage html 3 4 Name Stmts Miss Branch BrPart Cover


test 6 0 2 0 100% }}}

Possibly related to bug #146?

Comments (2)

  1. Log in to comment