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: assertRaises should return the "captured" exception
Type: enhancement Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: assertRaises should return the exception in its simple form
View: 28135
Assigned To: Nosy List: facundobatista, r.david.murray
Priority: normal Keywords:

Created on 2018-01-03 15:41 by facundobatista, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg309414 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2018-01-03 15:41
Sometimes it's nice to do extra checks on the error raised and captured by self.assertRaises call.

Yes, the same can be achieved using assertRaises as a context manager and then accessing the `exception` attribute in the context manager, but it looks too cumbersome to just get the exception, when it can be simply returned by the assertRaises call.

Note 1: Currently it returns None, so no backward compatibility problem.

Note 2: assertRaises in testtools does this and is very useful
msg309415 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-01-03 16:11
This has been proposed and rejected before, for example in issue 28135.  If you want to pursue it you'll need to start a thread on python-ideas.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76668
2018-01-03 16:11:31r.david.murraysetstatus: open -> closed

superseder: assertRaises should return the exception in its simple form

nosy: + r.david.murray
messages: + msg309415
resolution: duplicate
stage: needs patch -> resolved
2018-01-03 15:41:56facundobatistacreate