Skip to content

Instantly share code, notes, and snippets.

@xavfernandez
Last active August 29, 2015 13:57
Show Gist options
  • Save xavfernandez/9782553 to your computer and use it in GitHub Desktop.
Save xavfernandez/9782553 to your computer and use it in GitHub Desktop.
Mock asyncio call
from unittest import mock
import asyncio
@asyncio.coroutine
def test():
yield from range(10)
@asyncio.coroutine
def test2():
yield from test()
m = mock.MagicMock()
m.iter.return_value = range(5)
test = mock.Mock(return_value=m)
loop = asyncio.get_event_loop()
loop.run_until_complete(test2())
print(m.__iter__.call_count)
@ValeryKV
Copy link

ValeryKV commented Apr 8, 2015

Hi,

I ran this code with python3.4 and it printed "1". Shouldn't it be "5"?

Regards,
Valery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment