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.

classification
Title: Mock could check for exceptions in side effect list
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: eric.araujo, michael.foord, python-dev, r.david.murray
Priority: normal Keywords: easy

Created on 2012-04-20 20:38 by r.david.murray, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg158883 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-20 20:38
I just spent an hour figuring out why my test was failing because I tried to do this:

   mymock.side_effect = (AuthenticationError, None)

expecting the first call to raise an auth error and the second time it was called to get a normal return.

Since there are almost zero circumstances in which one would really want to return an exception, is there any reason not to have mock check for exceptions and raise them in this circumstance?  (If one did need to return an exception one could write a function...which is what one has to do now for the above case, but the above case seems more commonly needed than returning an exception would be.)
msg158896 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2012-04-20 22:38
Seems like a good change.
msg158922 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-21 14:52
New changeset c310233b1d64 by Michael Foord in branch 'default':
Closes issue 14636. mock objects raise exceptions from an iterable side_effect
http://hg.python.org/cpython/rev/c310233b1d64
History
Date User Action Args
2022-04-11 14:57:29adminsetgithub: 58841
2012-04-21 14:52:19python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg158922

resolution: fixed
stage: needs patch -> resolved
2012-04-20 22:38:08michael.foordsetassignee: michael.foord
messages: + msg158896
2012-04-20 21:55:57eric.araujosetnosy: + eric.araujo
2012-04-20 20:38:09r.david.murraycreate