classification
Title: assertRaises as a context manager should accept a 'msg' keyword argument.
Type: enhancement Stage: committed/rejected
Components: Versions: Python 3.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: SilentGhost, Winston.Ewert, brian.curtin, daniel.urban, ezio.melotti, michael.foord, python-dev, r.david.murray, rhettinger, robquad
Priority: normal Keywords: easy, patch

Created on 2010-12-26 19:18 by r.david.murray, last changed 2011-05-06 12:07 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
patch.diff Winston.Ewert, 2011-02-16 01:14 patch review
issue10775-2.diff ezio.melotti, 2011-04-30 10:54 review
Messages (15)
msg124675 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-26 19:18
assertRaises used as a method can't take a msg keyword argument because all args and keywords are passed to the callable.  But in context manager form it could, and this can be useful.  See, for example, issue 3583.
msg125169 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-01-03 13:48
I'm fine with this functionality being added in 3.3.
msg128623 - (view) Author: Winston Ewert (Winston.Ewert) Date: 2011-02-16 01:14
I decided to try my hand at writing a patch for python.

I ended up implementing the behavior for assertRaises, assertRaisesRegex, assertWarns, and assertWarnsRegex. I also made those functions complain about other arguments rather then just ignoring them.
msg130840 - (view) Author: Robbie Clemons (robquad) Date: 2011-03-14 16:02
Changing callableObj to callable_obj in assertRaises will break for anyone that's upgrading to 3.3.  I left a comment on the review.
msg130897 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-03-14 20:58
Aren't such use cases already covered by assertRaisesRegex?
msg130907 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-14 21:31
How does assertRaisesRegex address the use case in issue 3583?
msg130943 - (view) Author: Winston Ewert (Winston.Ewert) Date: 2011-03-15 01:56
robquad mentions having left a comment on the review, but I'm not seeing how to view it. Can somebody explain?

It wasn't necessary to change the callable_obj bit, but both form were being used so I thought it best to standardize. Neither version of the parameter name shows up in the documentation.
msg130966 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-03-15 12:20
Michael pointed out that I had completely missed the point of what the "msg" argument was about. Sorry for the noise.
msg130968 - (view) Author: SilentGhost (SilentGhost) Date: 2011-03-15 13:04
> I left a comment on the review.
You need to publish your comment if you want others to see it.
msg130970 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2011-03-15 13:17
I showed robquad how to do the review stuff at PyCon but I forgot about the publish part. Robbie, if you hit "Publish + Mail Comments" near the top of the page after you've left comments, it'll send them out.


What he noticed was that changing to callable_obj in the assertRaises signature could break anyone who had been using callableObj as a named argument. Although it isn't explicitly documented, it's a named argument that someone is probably using. As for standardizing, it's probably best to match the general format of the library which is camelCase, and change the internal uses rather than a public method signature.
msg130988 - (view) Author: Winston Ewert (Winston.Ewert) Date: 2011-03-15 16:15
The public methods were using both callable_obj and callableObj. Perhaps the patch should standardize on callableObj and accept callable_obj with a warning?
msg134849 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-30 10:54
Attached a revised patch.
While I agree that an error should be raised when extra args are provided in the context manager form, this is out of the scope of the issue, so I didn't include those changes.
msg135276 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-05-06 11:03
New patch by Ezio looks good to me. Go ahead and commit. Please raise a separate issue for error reporting when invalid argument combinations are used. (i.e. additional keyword arguments but no callable.)
msg135278 - (view) Author: Roundup Robot (python-dev) Date: 2011-05-06 12:02
New changeset 8fc801ca9ea1 by Ezio Melotti in branch 'default':
Issue #10775: assertRaises, assertRaisesRegex, assertWarns, and assertWarnsRegex now accept a keyword argument 'msg' when used as context managers.  Initial patch by Winston Ewert.
http://hg.python.org/cpython/rev/8fc801ca9ea1
msg135279 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-05-06 12:07
Done, thanks for the patch!
History
Date User Action Args
2011-05-06 12:07:25ezio.melottisetstatus: open -> closed
resolution: accepted
messages: + msg135279

stage: patch review -> committed/rejected
2011-05-06 12:02:49python-devsetnosy: + python-dev
messages: + msg135278
2011-05-06 11:03:01michael.foordsetmessages: + msg135276
2011-05-05 12:19:59ncoghlansetnosy: - ncoghlan
2011-04-30 10:55:41ezio.melottisetfiles: - issue10775-2.diff
2011-04-30 10:55:28ezio.melottisetfiles: + issue10775-2.diff
2011-04-30 10:54:04ezio.melottisetfiles: + issue10775-2.diff

messages: + msg134849
stage: needs patch -> patch review
2011-04-30 09:00:14ezio.melottisetassignee: michael.foord -> ezio.melotti
2011-03-15 16:58:46michael.foordsetassignee: michael.foord
nosy: rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, brian.curtin, SilentGhost, daniel.urban, Winston.Ewert, robquad
2011-03-15 16:15:46Winston.Ewertsetnosy: rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, brian.curtin, SilentGhost, daniel.urban, Winston.Ewert, robquad
messages: + msg130988
2011-03-15 13:17:15brian.curtinsetnosy: + brian.curtin
messages: + msg130970
2011-03-15 13:04:23SilentGhostsetnosy: + SilentGhost
messages: + msg130968
2011-03-15 12:20:55ncoghlansetnosy: rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, daniel.urban, Winston.Ewert, robquad
messages: + msg130966
2011-03-15 01:56:49Winston.Ewertsetnosy: rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, daniel.urban, Winston.Ewert, robquad
messages: + msg130943
2011-03-14 21:31:08r.david.murraysetnosy: rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, daniel.urban, Winston.Ewert, robquad
messages: + msg130907
2011-03-14 20:58:20ncoghlansetnosy: + ncoghlan
messages: + msg130897
2011-03-14 16:02:52robquadsetnosy: + robquad
messages: + msg130840
2011-02-16 01:14:40Winston.Ewertsetfiles: + patch.diff

nosy: + Winston.Ewert
messages: + msg128623

keywords: + patch
2011-01-21 08:33:43daniel.urbansetnosy: + daniel.urban
2011-01-21 05:22:16ezio.melottisetnosy: + ezio.melotti
2011-01-03 13:48:46michael.foordsetmessages: + msg125169
2010-12-26 19:30:18r.david.murraylinkissue3583 dependencies
2010-12-26 19:18:47r.david.murraycreate