Skip to content

Incorrect branch coverage when running two async iterators #1176

Closed
@sfstpala

Description

@sfstpala

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcpythonReported as a bug in CPython

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions