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.04:19:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426306773.6.0.983342092418.issue23661@psf.upfronthosting.co.za>
In-reply-to
Content
The problem only affects autospecced functions.

Apparently, the problem lies here (all code excerpts from Lib/unittest/mock.py):

- When autospeccing functions, the Mock._mock_delegate field is populated at the end of _setup_func (and its the only place I found where the delegate is set):

197 def _setup_func(funcopy, mock):
[...]
237     mock._mock_delegate = funcopy

- Mock.side_effect is a property, and proxies the get/set to _mock_delegate when it exists, and on the way out does not detect the exception and tries to make an _IterMock out of it and everything explodes.

 504     def __get_side_effect(self):
 505         delegated = self._mock_delegate
 506         if delegated is None:
 507             return self._mock_side_effect
 508         sf = delegated.side_effect
 509         if sf is not None and not callable(sf) and not isinstance(sf, _MockIter):
 510             sf = _MockIter(sf)

I've attached a patch which adds a test for this use case, and a proposed fix. Hope it helps :)
History
Date User Action Args
2015-03-14 04:19:33Ignacio Rossisetrecipients: + Ignacio Rossi
2015-03-14 04:19:33Ignacio Rossisetmessageid: <1426306773.6.0.983342092418.issue23661@psf.upfronthosting.co.za>
2015-03-14 04:19:33Ignacio Rossilinkissue23661 messages
2015-03-14 04:19:33Ignacio Rossicreate