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.

Author denversc
Recipients denversc, kristjan.jonsson, michael.foord
Date 2010-08-13.14:57:40
SpamBayes Score 1.9659108e-11
Marked as misclassified No
Message-id <1281711464.19.0.685530938413.issue9587@psf.upfronthosting.co.za>
In-reply-to
Content
It would be great if unittest.assertRaises() returned the raised exception when it passes.  This allows the caller to easily perform further checks on the exception, such as its attribute values.  Currently assertRaises() returns None (when it doesn't return a context manager) so changing the return value should not break backwards compatibility.

I see that this was already discussed in issue6275 but I'd like to resurrect the discussion since this is a common scenario in my unit tests, and I assume others.  Revisions r76238 and r78110 added the ability to get the exception from the context manager (good) but sometimes using the context manager approach adds unnecessary bloat to already long-winded unit tests.

I've attached a possible patch for the py3k branch (unittest.assertRaises.returnex.v1.patch).  Thank you for (re)considering this topic :)  Also, thank you Michael Foord for your recent improvements to unittest... the new features are very much appreciated!
History
Date User Action Args
2010-08-13 14:57:44denverscsetrecipients: + denversc, kristjan.jonsson, michael.foord
2010-08-13 14:57:44denverscsetmessageid: <1281711464.19.0.685530938413.issue9587@psf.upfronthosting.co.za>
2010-08-13 14:57:42denversclinkissue9587 messages
2010-08-13 14:57:41denversccreate