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: unittest hides traceback frames in chained exceptions
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: duplicate
Dependencies: Superseder: unittest swallows part of stack trace when raising AssertionError in a TestCase
View: 24959
Assigned To: Nosy List: dseomn, iritkatriel
Priority: normal Keywords: patch

Created on 2020-11-02 18:25 by dseomn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
foo.py dseomn, 2020-11-02 18:25
Pull Requests
URL Status Linked Edit
PR 23687 iritkatriel, 2020-12-08 01:47
PR 23688 open iritkatriel, 2020-12-08 01:48
Messages (3)
msg380244 - (view) Author: David Mandelberg (dseomn) Date: 2020-11-02 18:25
The traceback in the output of the attached test (see below) doesn't include line 5, which is where the original exception is raised. I think this is because https://github.com/python/cpython/blob/b9ee4af4c643a323779fd7076e80b29d611f2709/Lib/unittest/result.py#L180-L186 uses the `limit` parameter to try to hide the implementation of `self.fail()` from the traceback, but `traceback.TracebackException.format()` applies the limit to the chained exception. I'm not sure if that's a bug in unittest or traceback, but from the comment in the above part of unittest, I don't think it's intentional.


F
======================================================================
FAIL: test_foo (__main__.FooTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "foo.py", line 12, in test_foo
    foo()
ValueError: foo

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo.py", line 14, in test_foo
    self.fail('foo() raised ValueError')
AssertionError: foo() raised ValueError

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
msg382705 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-12-08 01:56
I made a patch that replaces the limit hack by a filter on the traceback. We could stop here an just fix this, or we could create a more generic filter in the traceback module as suggested in issue31299.
msg390489 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-04-07 22:07
I think this is the same as issue37712.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86413
2021-04-09 13:31:56iritkatrielsetstatus: open -> closed
superseder: unittest swallows part of stack trace when raising AssertionError in a TestCase
resolution: duplicate
stage: patch review -> resolved
2021-04-07 22:07:07iritkatrielsetmessages: + msg390489
2020-12-08 01:56:34iritkatrielsetmessages: + msg382705
2020-12-08 01:48:58iritkatrielsetpull_requests: + pull_request22556
2020-12-08 01:47:52iritkatrielsetpull_requests: + pull_request22555
2020-12-08 01:47:35iritkatrielsetpull_requests: - pull_request22552
2020-12-08 01:46:55iritkatrielsetpull_requests: + pull_request22552
2020-12-08 01:46:10iritkatrielsetpull_requests: - pull_request22552
2020-12-08 01:43:56iritkatrielsetversions: + Python 3.10, - Python 3.8
2020-12-08 01:36:15iritkatrielsetkeywords: + patch
nosy: + iritkatriel

pull_requests: + pull_request22552
stage: patch review
2020-11-02 18:25:59dseomncreate