[TIP] 'Mock' object is not iterable

Andrea Crotti andrea.crotti.0 at gmail.com
Mon Mar 26 06:52:34 PDT 2012

On 03/26/2012 02:47 PM, Michael Foord wrote:
> __init__ methods can't return anything. Try it :-)
> (Maybe you meant something else though? You could set 
> "ret.return_value = ret".)

Yes sorry I meant __call__ probably.

I think the following should/might work:

m = Mock()
m.return_iterator.return_value = [1,2,3]

and then

for x in in m().return_iterator():

and supposing m() return self it should work, right?
I was looking at _mock_call to understand what it does and it returns 
something, but it's a bit
too complicated to understand what exactly for me now..

More information about the testing-in-python mailing list