Branch coverage does weird things for yield statements

Issue #482 duplicate
Tristan Seligmann
created an issue

Consider this example:

def gen(): 
    print 'hi mom!' 
    yield 42 
    print 'not covered' 
print gen().next() 

If I run it without --branch, coverage tells me the first print and yield are executed, but the third print isn't; all as expected.

If I run it with --branch, coverage tells me the first print was executed, but that the yield was not executed at all. Huh?

Comments (2)

  1. Pi Delport

    This makes partial sense: the yield is an expression that branches control flow, and doesn't actually fully cover the line until control is resumed back into the generator. For example, consider:

    def gen():
        print('hi mom!')
        print((yield 42), 1 / 0)
        print('not covered')
    
    print gen().next()
    

    However, that doesn't explain why it counts the yield line as completely missed instead of partial.

  2. Log in to comment