[TIP] Using Mock to patch an iterator / generator?
andrew.george.hammond at gmail.com
Thu Jun 9 16:08:40 PDT 2011
I have a class that looks like
for r in something_iterable:
I would like to mock the class and patch Foo.iter. I have tried a number of
things without luck.
_partitions = 
for p in self._partitions:
self._partitions = [ 1, 2, 3, 4 ]
rw = Mock(spec=Foo)
self.mock_RollingWindow = rw
rw.iter = Mock()
rw.iter.side_effect = self.partitions
This is following the pattern I've used for other methods, but doesn't work
for an iterator... so, what is the proper approach please?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python