classification
Title: unittest.mock: side_effect iterators ignore DEFAULT
Type: behavior Stage: resolved
Components: Versions: Python 3.4, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: Chaka_bum, asvetlov, michael.foord, python-dev, raduv
Priority: normal Keywords: easy, patch

Created on 2013-03-21 03:05 by michael.foord, last changed 2013-04-08 10:20 by asvetlov. This issue is now closed.

Files
File name Uploaded Description Edit
issue_17502.patch Chaka_bum, 2013-04-07 12:46 review
Messages (7)
msg184836 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-03-21 03:05
An iterator set as a mock side_effect should be able to include mock.DEFAULT to use the standard return value.


    def test_side_effect_iterator_default(self):
        mock = Mock(return_value=2)
        mock.side_effect = [1, DEFAULT]
        result = mock(), mock()
        self.assertEqual(result, (1, 2))
msg185074 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-03-23 19:03
There's a straightforward patch here, it just needs applying:

http://code.google.com/p/mock/issues/attachmentText?id=190&aid=1900000000&name=mock.patch&token=6pDNkNBcNLDftg-PsUE8roPb6T4%3A1363712167613
msg186202 - (view) Author: Yuriy Senko (Chaka_bum) * Date: 2013-04-07 12:46
Patch ported from http://code.google.com/p/mock/issues/attachmentText?id=190&aid=1900000000&name=mock.patch&token=6pDNkNBcNLDftg-PsUE8roPb6T4%3A1363712167613
msg186207 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2013-04-07 13:44
Fixed. Thanks
msg186282 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-04-08 09:57
This was committed without NEWS entry or documentation update.
msg186287 - (view) Author: Roundup Robot (python-dev) Date: 2013-04-08 10:19
New changeset 4d8e9c5ba651 by Andrew Svetlov in branch '3.3':
Add NEWS entry for #17502: Process DEFAULT values in mock side_effect that returns iterator.
http://hg.python.org/cpython/rev/4d8e9c5ba651

New changeset f82fb8813407 by Andrew Svetlov in branch 'default':
Add NEWS entry for #17502: Process DEFAULT values in mock side_effect that returns iterator.
http://hg.python.org/cpython/rev/f82fb8813407
msg186288 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2013-04-08 10:20
NEWS updated, thanks.
History
Date User Action Args
2013-04-08 10:20:08asvetlovsetmessages: + msg186288
2013-04-08 10:19:18python-devsetnosy: + python-dev
messages: + msg186287
2013-04-08 09:57:32michael.foordsetmessages: + msg186282
2013-04-07 13:44:45asvetlovsetstatus: open -> closed
resolution: fixed
messages: + msg186207

stage: needs patch -> resolved
2013-04-07 12:46:44Chaka_bumsetfiles: + issue_17502.patch

nosy: + Chaka_bum, asvetlov
messages: + msg186202

keywords: + patch
2013-03-27 23:37:45raduvsetnosy: + raduv
2013-03-23 19:03:51michael.foordsetmessages: + msg185074
2013-03-21 03:05:40michael.foordcreate