[TIP] list side_effect -> "list is not an iterator"
Michael Foord
fuzzyman at voidspace.org.uk
Mon Apr 22 06:10:26 PDT 2013
On 19 Apr 2013, at 22:08, Chris Conway <clconway at google.com> wrote:
> 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)
>
I'm pretty sure this is a bug in mock. You can get round it with: fn.side_effect = iter([1, 2])
That's obviously not ideal. I'm hoping to have a proper look at it tonight and I'll come back to you.
Thanks,
Michael
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing
http://www.sqlite.org/different.html
More information about the testing-in-python
mailing list