This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Ignacio Rossi
Recipients Ignacio Rossi
Date 2015-03-14.00:45:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426293940.15.0.253058774664.issue23661@psf.upfronthosting.co.za>
In-reply-to
Content
The following fails on python 3.4.2, 3.4.3 and 3.5.0a2 (downloaded from python.org and compiled on Ubuntu 14.04). 
The same happens when using mock.patch with autospec=True.

>>> from unittest.mock import create_autospec
>>> def function():
...     pass
... 
>>> mock = create_autospec(function)
>>> mock.side_effect = ValueError('MyError')
>>> mock()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 3, in function
  File "/usr/local/lib/python3.5/unittest/mock.py", line 910, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/usr/local/lib/python3.5/unittest/mock.py", line 963, in _mock_call
    effect = self.side_effect
  File "/usr/local/lib/python3.5/unittest/mock.py", line 510, in __get_side_effect
    sf = _MockIter(sf)
  File "/usr/local/lib/python3.5/unittest/mock.py", line 351, in __init__
    self.obj = iter(obj)
TypeError: 'ValueError' object is not iterable

But, on Python 3.3.5, 3.4.0, or when the mock is created via Mock(), for  instance, the exception is raised as expected:

[...]
>>> mock()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 3, in function
  File "/usr/lib/python3.4/unittest/mock.py", line 885, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/usr/lib/python3.4/unittest/mock.py", line 941, in _mock_call
    raise effect
ValueError: MyError
History
Date User Action Args
2015-03-14 00:45:40Ignacio Rossisetrecipients: + Ignacio Rossi
2015-03-14 00:45:40Ignacio Rossisetmessageid: <1426293940.15.0.253058774664.issue23661@psf.upfronthosting.co.za>
2015-03-14 00:45:40Ignacio Rossilinkissue23661 messages
2015-03-14 00:45:39Ignacio Rossicreate