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: support "with self.assertRaises(SomeException) as exc:" syntax
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, ezio.melotti, flox, georg.brandl, michael.foord, pitrou, rhettinger
Priority: normal Keywords:

Created on 2010-02-05 17:02 by flox, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (11)
msg98882 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-05 17:02
It would be useful to get the actual exception in order to introspect its attributes.

(See some potential uses in "test_dict")
msg98883 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-02-05 17:03
You can't get the exception before it is even raised...
msg98884 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-05 17:09
right, but it could return a wrapper object which receives the exception on __exit__.
msg98886 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-02-05 17:15
Indeed. In that case, I am all for it.
msg98889 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-02-05 17:43
Too clever by far.
msg98930 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-02-06 02:23
I'd prefer for the magic context manager to be returned.
msg98985 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-02-07 09:12
Why not the un-magic context manager, which has an exc_value attribute with the exception?
msg99004 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-02-07 15:21
2010/2/7 Georg Brandl <report@bugs.python.org>:
>
> Georg Brandl <georg@python.org> added the comment:
>
> Why not the un-magic context manager, which has an exc_value attribute with the exception?

That's what I meant, but our perceptions of magic are clearly different. :)
msg99006 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-02-07 16:52
Just use the context manager and the exception is available as exc_value.
msg99008 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-07 18:29
Thank you for this answer. The "exception" argument could be useful.
But it does not work as documented on r77999...

Btw, the documentation explains the behaviour I expect...
msg99009 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-07 18:50
Fixed (with tests) in r78094. Thank you Michael.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52107
2010-02-07 18:50:10floxsetmessages: + msg99009
2010-02-07 18:49:36michael.foordsetstatus: pending -> closed
2010-02-07 18:29:56floxsetstatus: closed -> pending

messages: + msg99008
2010-02-07 16:52:48michael.foordsetstatus: open -> closed

nosy: + michael.foord
messages: + msg99006

resolution: rejected
stage: needs patch -> resolved
2010-02-07 15:21:21benjamin.petersonsetmessages: + msg99004
2010-02-07 09:12:42georg.brandlsetnosy: + georg.brandl
messages: + msg98985
2010-02-06 02:23:24benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg98930
2010-02-05 17:43:07rhettingersetnosy: + rhettinger
messages: + msg98889
2010-02-05 17:15:12pitrousetmessages: + msg98886
2010-02-05 17:14:30ezio.melottisetnosy: + ezio.melotti

stage: needs patch
2010-02-05 17:09:20floxsetmessages: + msg98884
2010-02-05 17:03:44pitrousetnosy: + pitrou
messages: + msg98883
2010-02-05 17:02:08floxcreate