निम्नलिखित कोड TypeError: 'Mock' object is not iterable
ImBeingTested.i_call_other_coroutines
में विफल रहता है क्योंकि मैंने ImGoingToBeMocked
को एक मॉक ऑब्जेक्ट से बदल दिया है।एसिन्सीओ कोरआउट्स का नकल कैसे करें?
मैं कोरउटिन का नकल कैसे कर सकता हूं?
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())
खैर यह स्पष्ट है और अब मैं सवाल पूछने के लिए गूंगा है! धन्यवाद! –
मैंने इसे इस जवाब में एक सहायक और सामान के साथ विस्तारित किया: http://stackoverflow.com/a/29905620/23972 –