Issue 10775: assertRaises as a context manager should accept a 'msg' keyword argument. (original) (raw)

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 2022-04-11 14:57 by admin. 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: Alyssa 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: Alyssa 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) * (Python triager) 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) (Python triager) 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
2022-04-11 14:57:10 admin set github: 54984
2011-05-06 12:07:25 ezio.melotti set status: open -> closedresolution: acceptedmessages: + stage: patch review -> resolved
2011-05-06 12:02:49 python-dev set nosy: + python-devmessages: +
2011-05-06 11:03:01 michael.foord set messages: +
2011-05-05 12:19:59 ncoghlan set nosy: - ncoghlan
2011-04-30 10:55:41 ezio.melotti set files: - issue10775-2.diff
2011-04-30 10:55:28 ezio.melotti set files: + issue10775-2.diff
2011-04-30 10:54:04 ezio.melotti set files: + issue10775-2.diffmessages: + stage: needs patch -> patch review
2011-04-30 09:00:14 ezio.melotti set assignee: michael.foord -> ezio.melotti
2011-03-15 16:58:46 michael.foord set assignee: michael.foordnosy:rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, brian.curtin, SilentGhost, daniel.urban, Winston.Ewert, robquad
2011-03-15 16:15:46 Winston.Ewert set nosy:rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, brian.curtin, SilentGhost, daniel.urban, Winston.Ewert, robquadmessages: +
2011-03-15 13:17:15 brian.curtin set nosy: + brian.curtinmessages: +
2011-03-15 13:04:23 SilentGhost set nosy: + SilentGhostmessages: +
2011-03-15 12:20:55 ncoghlan set nosy:rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, daniel.urban, Winston.Ewert, robquadmessages: +
2011-03-15 01:56:49 Winston.Ewert set nosy:rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, daniel.urban, Winston.Ewert, robquadmessages: +
2011-03-14 21:31:08 r.david.murray set nosy:rhettinger, ncoghlan, ezio.melotti, r.david.murray, michael.foord, daniel.urban, Winston.Ewert, robquadmessages: +
2011-03-14 20:58:20 ncoghlan set nosy: + ncoghlanmessages: +
2011-03-14 16:02:52 robquad set nosy: + robquadmessages: +
2011-02-16 01:14:40 Winston.Ewert set files: + patch.diffnosy: + Winston.Ewertmessages: + keywords: + patch
2011-01-21 08:33:43 daniel.urban set nosy: + daniel.urban
2011-01-21 05:22:16 ezio.melotti set nosy: + ezio.melotti
2011-01-03 13:48:46 michael.foord set messages: +
2010-12-26 19:30:18 r.david.murray link issue3583 dependencies
2010-12-26 19🔞47 r.david.murray create