Skip to content

Incorrect branch coverage when running two async iterators #1176

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

Closed
sfstpala opened this issue Jun 15, 2021 · 4 comments
Closed

Incorrect branch coverage when running two async iterators #1176

sfstpala opened this issue Jun 15, 2021 · 4 comments
Labels
bug Something isn't working cpython Reported as a bug in CPython

Comments

@sfstpala
Copy link

Describe the bug
When I run two (or more) async iterators in async for loops, the second loop will have incorrect branch coverage.

To Reproduce
Here's an example:

import asyncio

class AsyncIter:

    def __init__(self, items):
        self.items = items

    async def __aiter__(self):
        for i in self.items:
            yield i

async def test():
    async for i in AsyncIter([1, 2, 3]):
        pass
    async for i in AsyncIter([1, 2, 3]):
        pass

asyncio.run(test())

And the result:

Screenshot 2021-06-15 at 05 20 21

I'm running Coverage 5.5 on Python 3.9 (debug sys output here)

Expected behavior
Same as the non-async version:

Screenshot 2021-06-15 at 05 22 14

@sfstpala sfstpala added the bug Something isn't working label Jun 15, 2021
@sfstpala
Copy link
Author

I get the same issue when I just put the async for in another loop like this:

async def test():
    for i in [1]:
        async for i in AsyncIter([1, 2, 3]):
            pass

@sfstpala
Copy link
Author

I also noticed that this works fine in Python 3.8, but not in Python 3.9 and 3.10.

@nedbat
Copy link
Owner

nedbat commented Jun 23, 2021

See this comment on #1158.

@nedbat
Copy link
Owner

nedbat commented Jul 13, 2021

I think this is a combination of two CPython bugs:
async-for loops are traced incorrectly in Python 3.10 and Python 3.9 traces async for/else incorrectly.

@nedbat nedbat added the cpython Reported as a bug in CPython label Jul 19, 2021
nedbat added a commit that referenced this issue Jul 19, 2021
@nedbat nedbat closed this as completed Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cpython Reported as a bug in CPython
Projects
None yet
Development

No branches or pull requests

2 participants