[TIP] 'Mock' object is not iterable

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

I'm trying to mock out a function which looks for orphaned pyc files in 
the filesystem.

So I created something like this

def fmock_b():
     ret = Mock()
     ret.pesky_pyc.return_value = ['b.pyc']
     return ret

and the function I'm testing does this:
     for pyc in Walker(directory).pesky_pyc():

but I get the error TypeError: 'Mock' object is not iterable

But why?

Actually also the non mocked version of Walker doesn't return a an 
iterable from __init__, it's
pesky_pyc that returns an iterable, so why does it complain?

Any hint about how to fix it?


More information about the testing-in-python mailing list