gh-105292: Add option to make traceback.TracebackException.format_exception_only recurse into exception groups (#105294)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Irit Katriel 2023-06-06 10:26:18 +01:00 committed by GitHub
parent 92022d8416
commit f4d8e10d0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 13 deletions

View file

@ -2792,6 +2792,20 @@ class TestTracebackException_ExceptionGroups(unittest.TestCase):
self.assertEqual(formatted, expected)
def test_exception_group_format_exception_onlyi_recursive(self):
teg = traceback.TracebackException.from_exception(self.eg)
formatted = ''.join(teg.format_exception_only(show_group=True)).split('\n')
expected = [
'ExceptionGroup: eg2 (2 sub-exceptions)',
' ExceptionGroup: eg1 (2 sub-exceptions)',
' ZeroDivisionError: division by zero',
' ValueError: 42',
' ValueError: 24',
''
]
self.assertEqual(formatted, expected)
def test_exception_group_format(self):
teg = traceback.TracebackException.from_exception(self.eg)