I have a method I use for testing async code in Python (3.6):
@asyncio.coroutine
def coroutine_creater(value):
return value
I use it like this:
async def test_test():
my_mock = Mock(return_value=coroutine_creater(5))
# I call with "await"
first_call = await my_mock()
second_call = await my_mock()
assert first_call == 5, 'first call failed'
assert second_call == 5, 'second call failed' # this call fails
This way I can create mocks for async calls. I found that this doesn't work if I call the async method twice. In my code, first_call equals 5 like I expect, but second_call equals None. What's going on here? What can I do to test code that calls a Mock async method multiple times?