This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author natim
Recipients asvetlov, natim, yselivanov
Date 2019-03-07.09:08:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551949721.3.0.00931012089501.issue36222@roundup.psfhosted.org>
In-reply-to
Content
Refs: https://github.com/Martiusweb/asynctest/issues/114

I was trying to mock a `asyncio.run(asyncio.gather())` call and I discovered that while it was working with `loop.run_until_complete` it wasn't with `asyncio.run`

Is there a reason for this difference of behaviour?

```
import asyncio
from unittest.mock import Mock


class AsyncMock(Mock):

    def __call__(self, *args, **kwargs):
        sup = super(AsyncMock, self)
        async def coro():
            return sup.__call__(*args, **kwargs)
        return coro()

    def __await__(self):
        return self().__await__()

mocked_function = AsyncMock()

asyncio.run(asyncio.gather(mocked_function()))
```

```
import asyncio
from unittest.mock import Mock


class AsyncMock(Mock):

    def __call__(self, *args, **kwargs):
        sup = super(AsyncMock, self)
        async def coro():
            return sup.__call__(*args, **kwargs)
        return coro()

    def __await__(self):
        return self().__await__()

mocked_function = AsyncMock()

loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(mocked_function()))
```
History
Date User Action Args
2019-03-07 09:08:41natimsetrecipients: + natim, asvetlov, yselivanov
2019-03-07 09:08:41natimsetmessageid: <1551949721.3.0.00931012089501.issue36222@roundup.psfhosted.org>
2019-03-07 09:08:41natimlinkissue36222 messages
2019-03-07 09:08:41natimcreate