Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect.isawaitable() returns False when the argument is a CoroutineMock #136

Open
thedrow opened this issue Jul 23, 2019 · 4 comments
Open

Comments

@thedrow
Copy link

thedrow commented Jul 23, 2019

Since a CoroutineMock is awaitable inspect.isawaitable() should return True.
These are the criteria for an awaitable object.

@Martiusweb
Copy link
Owner

CoroutineMock should be named CoroutineFunctionMock.

inspect.isawaitable(my_coro_mock()) # True.
This is intended.

@thedrow
Copy link
Author

thedrow commented Jul 23, 2019

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.

@Martiusweb
Copy link
Owner

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.

@Martiusweb
Copy link
Owner

Re-opening to add unit tests to ensure CoroutineMock is tested against inspect.isawaitable().

@Martiusweb Martiusweb reopened this Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants