Generator expression is marked as not executed when it clearly is

Issue #475 resolved
Ned Batchelder repo owner created an issue

In this code with branch coverage, "Line of interest" is marked as partial (3->-3)

def f(a, b):
    c = (i for i in a)
    d = (j for j in b)  # Line of interest
    return dict(zip(c, d))

print(f(['a', 'b'], [1, 2]))

Happens with 4.0.3 and 4.1b2+

Comments (3)

  1. Ned Batchelder reporter

    This is from http://stackoverflow.com/questions/35317757/python-unittest-branch-coverage-seems-to-miss-executed-generator-in-zip

    There, the problem was correctly identified: zip never exhausts the second iterator, because it stops as soon as the first iterator is done. So the second generator never got a chance to finish, so 3->-3 is missing.

    I would like to do a better job here, especially because work is underway to make 3->-3 be expressed as, "The generator expression on line 3 never ran," which is not true.

  2. Log in to comment