Mã sau không thành công với TypeError: 'Mock' object is not iterable
trong ImBeingTested.i_call_other_coroutines
vì tôi đã thay thế ImGoingToBeMocked
bằng đối tượng Mock.Làm thế nào để giả lập asyncio coroutines?
Tôi có thể thử nghiệm coroutines bằng cách nào?
class ImGoingToBeMocked:
@asyncio.coroutine
def yeah_im_not_going_to_run(self):
yield from asyncio.sleep(1)
return "sup"
class ImBeingTested:
def __init__(self, hidude):
self.hidude = hidude
@asyncio.coroutine
def i_call_other_coroutines(self):
return (yield from self.hidude.yeah_im_not_going_to_run())
class TestImBeingTested(unittest.TestCase):
def test_i_call_other_coroutines(self):
mocked = Mock(ImGoingToBeMocked)
ibt = ImBeingTested(mocked)
ret = asyncio.get_event_loop().run_until_complete(ibt.i_call_other_coroutines())
Vâng đây là rõ ràng và bây giờ tôi cảm thấy ngớ ngẩn cho đặt câu hỏi! Cảm ơn! –
Tôi mở rộng điều này với một người trợ giúp và các công cụ trong câu trả lời này: http://stackoverflow.com/a/29905620/23972 –