Last active
November 12, 2015 21:46
-
-
Save trecouvr/9782603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import unittest | |
| import unittest.mock | |
| class MyClass: | |
| @asyncio.coroutine | |
| def coro1(self): | |
| yield from self.coro2() | |
| @asyncio.coroutine | |
| def coro2(self): | |
| return True | |
| class MockTestCase(unittest.TestCase): | |
| def test_call_coro2(self): | |
| loop = asyncio.get_event_loop() | |
| m = MyClass() | |
| mm = unittest.mock.MagicMock() | |
| mm.iter.return_value = 'iterable' | |
| m.coro2 = unittest.mock.Mock(return_value=mm) | |
| coro = m.coro1() | |
| result = loop.run_until_complete(coro) | |
| self.assertEqual(1, mm.__iter__.call_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I run this, result is None; I'd expect it to be 'iterable' since that's what's being assigned for the return_value. Is there some way to actually set the return value for the mocked method?