How can I make mock-0.6 return a sequence of values?
Posted
by Chris R
on Stack Overflow
See other posts from Stack Overflow
or by Chris R
Published on 2010-03-26T17:16:20Z
Indexed on
2010/03/26
17:53 UTC
Read the original article
Hit count: 461
I'm using the mock-0.6 library from http://www.voidspace.org.uk/python/mock/mock.html to mock out a framework for testing, and I want to have a mock method return a series of values, each time it's called.
Right now, this is what I figured should work:
def returnList(items):
def sideEffect(*args, **kwargs):
for item in items:
yield item
yield mock.DEFAULT
return sideEffect
mock = Mock(side_effect=returnList(aListOfValues))
values = mock()
log.info("Got %s", values)
And the log output is this:
subsys: INFO: Got <generator object func at 0x1021db500>
So, the side effect is returning the generator, not the next value, which seems wrong. Where am I getting this wrong?
© Stack Overflow or respective owner