classification
Title: argparse unittest tracebacks are confusing if an error is raised when not expected
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: adam-collard, alclarks, brandtbucher, ezio.melotti, r.david.murray, taleinat
Priority: low Keywords: patch

Created on 2010-08-03 16:21 by r.david.murray, last changed 2020-02-21 08:49 by taleinat. This issue is now closed.

Files
File name Uploaded Description Edit
argparse_test_raise.patch r.david.murray, 2010-08-03 19:51 review
argparse-raise-from-None adam-collard, 2013-07-06 11:28 patch to use raise from None review
Pull Requests
URL Status Linked Edit
PR 17120 merged alclarks, 2019-11-12 11:53
Messages (8)
msg112625 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-03 16:21
In python3 if an error is raised from ErrorRaisingArgumentParser that is not caught by an assertRaises, unittest prints out the traceback, which is a chained traceback including the SystemExit that the argparse test suite catches in order to produce the ArgumentParserError that is actually of interest.  I think the argparse test suite should break that chain to make the tracebacks when failures happen more on-point.
msg112628 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-03 16:51
I can't find anyway to actually do what I suggested.  There doesn't seem to be any way to break the traceback chain.
msg112660 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-03 19:51
See issue 6210.  The attached patch uses the workaround from that issue.
msg174747 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2012-11-04 03:29
Presumably the implementation of PEP 409 on issue 6210 can be used to fix this problem.
msg192415 - (view) Author: Adam Collard (adam-collard) * Date: 2013-07-06 11:28
Use raise from None to avoid additional exception context
msg355801 - (view) Author: Alex (alclarks) * Date: 2019-11-01 09:43
I'm a newcomer looking to contribute - would it be a good idea for me to update one of the attached diffs and raise a pull request?
msg362390 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-02-21 08:48
New changeset d4331c56b4f6fe6f18caf19fc1ecf9fec14f7066 by alclarks in branch 'master':
bpo-9495: avoid confusing chained exception in argparse test (GH-17120)
https://github.com/python/cpython/commit/d4331c56b4f6fe6f18caf19fc1ecf9fec14f7066
msg362391 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-02-21 08:49
Thanks for the PR, Alex!
History
Date User Action Args
2020-02-21 08:49:27taleinatsetstatus: open -> closed
versions: + Python 3.9, - Python 3.3, Python 3.4
messages: + msg362391

resolution: fixed
stage: patch review -> resolved
2020-02-21 08:48:43taleinatsetnosy: + taleinat
messages: + msg362390
2019-11-12 11:53:49alclarkssetpull_requests: + pull_request16626
2019-11-04 16:53:37brandtbuchersetnosy: + brandtbucher
2019-11-01 09:43:04alclarkssetnosy: + alclarks
messages: + msg355801
2014-02-03 17:04:58BreamoreBoysetnosy: - BreamoreBoy
2013-07-25 04:07:16ezio.melottisetkeywords: - easy
nosy: + ezio.melotti
stage: needs patch -> patch review

versions: + Python 3.3, Python 3.4, - Python 3.1, Python 3.2
2013-07-06 11:28:38adam-collardsetfiles: + argparse-raise-from-None

messages: + msg192415
2013-01-31 10:52:28adam-collardsetnosy: + adam-collard
2012-11-04 03:29:28BreamoreBoysetnosy: + BreamoreBoy
messages: + msg174747
2010-08-03 19:51:29r.david.murraysetfiles: + argparse_test_raise.patch
keywords: + patch
messages: + msg112660
2010-08-03 16:51:45r.david.murraysetmessages: + msg112628
2010-08-03 16:21:53r.david.murraycreate