MCPcopy Index your code
hub / github.com/python/cpython / test_original_unraisablehook_err

Method test_original_unraisablehook_err

Lib/test/test_sys.py:1399–1437  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1397 self.assertEqual(lines[-1], 'ValueError: 42')
1398
1399 def test_original_unraisablehook_err(self):
1400 # bpo-22836: PyErr_WriteUnraisable() should give sensible reports
1401 class BrokenDel:
1402 def __del__(self):
1403 exc = ValueError("del is broken")
1404 # The following line is included in the traceback report:
1405 raise exc
1406
1407 class BrokenStrException(Exception):
1408 def __str__(self):
1409 raise Exception("str() is broken")
1410
1411 class BrokenExceptionDel:
1412 def __del__(self):
1413 exc = BrokenStrException()
1414 # The following line is included in the traceback report:
1415 raise exc
1416
1417 for test_class in (BrokenDel, BrokenExceptionDel):
1418 with self.subTest(test_class):
1419 obj = test_class()
1420 with test.support.captured_stderr() as stderr, \
1421 test.support.swap_attr(sys, 'unraisablehook',
1422 sys.__unraisablehook__):
1423 # Trigger obj.__del__()
1424 del obj
1425
1426 report = stderr.getvalue()
1427 self.assertIn("Exception ignored", report)
1428 self.assertIn(test_class.__del__.__qualname__, report)
1429 self.assertIn("test_sys.py", report)
1430 self.assertIn("raise exc", report)
1431 if test_class is BrokenExceptionDel:
1432 self.assertIn("BrokenStrException", report)
1433 self.assertIn("<exception str() failed>", report)
1434 else:
1435 self.assertIn("ValueError", report)
1436 self.assertIn("del is broken", report)
1437 self.assertEndsWith(report, "\n")
1438
1439 def test_original_unraisablehook_exception_qualname(self):
1440 # See bpo-41031, bpo-45083.

Callers

nothing calls this directly

Calls 4

assertInMethod · 0.80
assertEndsWithMethod · 0.80
subTestMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected