Skip to content

Conversation

@EvanKrall
Copy link

@EvanKrall EvanKrall commented May 18, 2018

I kept running into issues with asynctest.CoroutineMock and a_sync.block():

>>> import asynctest
>>> import a_sync
>>> import asyncio
>>> a_sync.block(asynctest.CoroutineMock(return_value=5))
<generator object CoroutineMock._mock_call.<locals>.proxy at 0x7f4113e57c50>
>>> asyncio.get_event_loop().run_until_complete(asynctest.CoroutineMock(return_value=5)())
5

This is because CoroutineMock returns a MagicMock for any undefined attribute access:

>>> foo = asynctest.CoroutineMock()
>>> foo.func
<MagicMock name='mock.func' id='139917444876440'>
>>> foo.bar
<MagicMock name='mock.bar' id='139917444622824'>
>>>

Since to_blocking currently checks async_func.func first (which is not a coroutine function), it treats the CoroutineMock like a sync function, even though:

>>> asyncio.iscoroutinefunction(foo)
True

@EvanKrall
Copy link
Author

I added tests and a tox configuration for running them (just install and run tox), but the important bit of this change is in a_sync.py. Let me know if you'd rather I take out the tests, or if you prefer a different test setup, etc.

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

Successfully merging this pull request may close these issues.

1 participant