Skip to content
Advertisement

Mocking async call in python 3.5

How do I mock async call from one native coroutine to other one using unittest.mock.patch?

I currently have quite an awkward solution:

JavaScript

Then

JavaScript

This works but looks ugly. Is there more pythonic way to do this?

Advertisement

Answer

The solution was actually quite simple: I just needed to convert __call__ method of mock into coroutine:

JavaScript

This works perfectly, when mock is called, code receives native coroutine

Example usage:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement