[TIP] list side_effect -> "list is not an iterator"

Chris Conway clconway at google.com
Fri Apr 19 14:08:17 PDT 2013


What am I doing wrong here?

>>> import mock
>>> fn = mock.Mock()
>>> fn.side_effect = [1,2]
>>> fn(), fn()
(1, 2)

but

>>> fn = mock.create_autospec(lambda: None)
>>> fn.side_effect = [1,2]
>>> fn(), fn()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 3, in funcopy
  File "mock.py", line 974, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "mock.py", line 1031, in _mock_call
    result = next(effect)
TypeError: list object is not an iterator

whereas

>>> fn = mock.create_autospec(lambda: None, side_effect=[1,2])
>>> fn(), fn()
(1, 2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130419/faa6c0b3/attachment.htm>


More information about the testing-in-python mailing list