New submission from Rémy Hubscher [:natim] <hubscher.r...@gmail.com>:
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())) ``` ---------- components: asyncio messages: 337374 nosy: asvetlov, natim, yselivanov priority: normal severity: normal status: open title: ValueError: a coroutine was expected with asyncio.run versions: Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36222> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com