When I was trying to mock an async function in unittest with MagicMock, I got this exception:
TypeError: object MagicMock can\'t be used in \'await\' expr
I ended up with this hack.
# monkey patch MagicMock async def async_magic(): pass MagicMock.__await__ = lambda x: async_magic().__await__()
It only works for MagicMock, not other pre-defined return_value