Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch coverage does weird things for yield statements #482

Closed
nedbat opened this issue Mar 14, 2016 · 2 comments
Closed

Branch coverage does weird things for yield statements #482

nedbat opened this issue Mar 14, 2016 · 2 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Mar 14, 2016

Originally reported by Tristan Seligmann (Bitbucket: mithrandi, GitHub: mithrandi)


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?


@nedbat
Copy link
Owner Author

nedbat commented Mar 14, 2016

Original comment by Pi Delport (Bitbucket: pjdelport, GitHub: pjdelport)


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.

@nedbat
Copy link
Owner Author

nedbat commented Mar 28, 2016

Duplicate of #440.

@nedbat nedbat closed this as completed Mar 28, 2016
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant