-
-
Save bossjones/38bf378e08949275f37a6202e895e602 to your computer and use it in GitHub Desktop.
Return multiple items from a mocked function with Python's mock.
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 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