asynctest
asynctest copied to clipboard
inspect.isawaitable() returns False when the argument is a CoroutineMock
Since a CoroutineMock is awaitable inspect.isawaitable() should return True.
These are the criteria for an awaitable object.
CoroutineMock should be named CoroutineFunctionMock.
inspect.isawaitable(my_coro_mock()) # True.
This is intended.
Here's a testcase:
In [2]: import inspect
In [3]: from asynctest import CoroutineMock
In [4]: inspect.isawaitable(CoroutineMock())
Out[4]: False
I'm using Python 3.7.3.
Yes, this is because CoroutineMock() is the mock of a coroutine function, which is not awaitable.
async def my_coro():
... # do something
inspect.isawaitable(my_coro) # False
inspect.isawaitable(my_coro()) # True
and thus: inspect.iswawaitable(CoroutineMock) # False inspect.iswawaitable(CoroutineMock()) # False inspect.iswawaitable(CoroutineMock()()) # True
Note that this is not actually enforced by the unit tests.
Re-opening to add unit tests to ensure CoroutineMock is tested against inspect.isawaitable().