Issue 7859: support "with self.assertRaises(SomeException) as exc:" syntax (original) (raw)
This issue has been migrated to GitHub: https://github.com/python/cpython/issues/52107
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) * ![]() |
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) * ![]() |
Date: 2010-02-05 17:03 |
You can't get the exception before it is even raised... | ||
msg98884 - (view) | Author: Florent Xicluna (flox) * ![]() |
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) * ![]() |
Date: 2010-02-05 17:15 |
Indeed. In that case, I am all for it. | ||
msg98889 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2010-02-05 17:43 |
Too clever by far. | ||
msg98930 - (view) | Author: Benjamin Peterson (benjamin.peterson) * ![]() |
Date: 2010-02-06 02:23 |
I'd prefer for the magic context manager to be returned. | ||
msg98985 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2010-02-07 18:50 |
Fixed (with tests) in r78094. Thank you Michael. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:57 | admin | set | github: 52107 |
2010-02-07 18:50:10 | flox | set | messages: + |
2010-02-07 18:49:36 | michael.foord | set | status: pending -> closed |
2010-02-07 18:29:56 | flox | set | status: closed -> pendingmessages: + |
2010-02-07 16:52:48 | michael.foord | set | status: open -> closednosy: + michael.foordmessages: + resolution: rejectedstage: needs patch -> resolved |
2010-02-07 15:21:21 | benjamin.peterson | set | messages: + |
2010-02-07 09:12:42 | georg.brandl | set | nosy: + georg.brandlmessages: + |
2010-02-06 02:23:24 | benjamin.peterson | set | nosy: + benjamin.petersonmessages: + |
2010-02-05 17:43:07 | rhettinger | set | nosy: + rhettingermessages: + |
2010-02-05 17:15:12 | pitrou | set | messages: + |
2010-02-05 17:14:30 | ezio.melotti | set | nosy: + ezio.melottistage: needs patch |
2010-02-05 17:09:20 | flox | set | messages: + |
2010-02-05 17:03:44 | pitrou | set | nosy: + pitroumessages: + |
2010-02-05 17:02:08 | flox | create |