-
-
Save aj07mm/c746d8ee0329e48acb62a211b955b1d0 to your computer and use it in GitHub Desktop.
Return multiple items from a mocked function with Python's mock.
This file contains 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 mock | |
def returnList(items): | |
def func(): | |
for item in items: | |
yield item | |
yield mock.DEFAULT | |
generator = func() | |
def effect(*args, **kwargs): | |
return generator.next() | |
return effect | |
m = mock.Mock() | |
m.side_effect = returnList([1,2,3]) | |
for i in ['a', 'b', 'c']: | |
print i, m() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment