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

Mock #2

Closed
Olegt0rr opened this issue Oct 22, 2017 · 2 comments
Closed

Mock #2

Olegt0rr opened this issue Oct 22, 2017 · 2 comments

Comments

@Olegt0rr
Copy link

Hi there!
What about unittest.mock in asyncio?

@kwarunek
Copy link
Owner

To be honest I left this issue due to lack of my understanding, sorry. A mock object cooperates perfectly with a futurized and can be used to mock/patch coroutines. Additionally in the meantime I've added helper - to mock async iterators.

@dapicester
Copy link

I bumped into this today and I managed to get it working like this:

class MyTest(unittest.TestCase):
  @mock('myfunction')
  @async_test
  async def test_myfunc(self, mock):
    mock.return_value = futurized(42)
    result = await myfunction()
    self.assertEqual(result, 42)

The key is to have the mock's return_value and/or side_effect to return futurized values.

When using the async_test decorator ensure that it is the closest decorator to the test function.

Hope this helps.

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

3 participants