bpo-45615: Add missing test for printing traceback for non-exception. Fix traceback.py (GH-30091)

This commit is contained in:
Irit Katriel 2022-01-02 09:34:03 +00:00 committed by GitHub
parent a09bc3a404
commit a82baed0e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 7 deletions

View file

@ -1060,6 +1060,22 @@ class TracebackFormatTests(unittest.TestCase):
self.assertIn('ExceptionGroup', output)
self.assertLessEqual(output.count('ExceptionGroup'), LIMIT)
@cpython_only
def test_print_exception_bad_type_capi(self):
from _testcapi import exception_print
with captured_output("stderr") as stderr:
exception_print(42)
self.assertEqual(
stderr.getvalue(),
('TypeError: print_exception(): '
'Exception expected for value, int found\n')
)
def test_print_exception_bad_type_python(self):
msg = "Exception expected for value, int found"
with self.assertRaisesRegex(TypeError, msg):
traceback.print_exception(42)
cause_message = (
"\nThe above exception was the direct cause "