summaryrefslogtreecommitdiff
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-22 23:44:02 +0200
committerGitHub <noreply@github.com>2019-05-22 23:44:02 +0200
commite4d300e07c33a9a77549c62d8687d8fe130c53d5 (patch)
tree165c92b9c1ff6f78bbffbcb4c7d68979091fc061 /Lib/test/test_exceptions.py
parent904e34d4e6b6007986dcc585d5c553ee8ae06f95 (diff)
downloadcpython-git-e4d300e07c33a9a77549c62d8687d8fe130c53d5.tar.gz
bpo-36829: Add test.support.catch_unraisable_exception() (GH-13490)
* Copy test_exceptions.test_unraisable() to test_sys.UnraisableHookTest(). * Use catch_unraisable_exception() in test_coroutines, test_exceptions, test_generators.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py30
1 files changed, 8 insertions, 22 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 6ef529e2b0..d7e11d2d30 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -12,6 +12,9 @@ from test.support import (TESTFN, captured_stderr, check_impl_detail,
check_warnings, cpython_only, gc_collect, run_unittest,
no_tracing, unlink, import_module, script_helper,
SuppressCrashReport)
+from test import support
+
+
class NaiveException(Exception):
def __init__(self, x):
self.x = x
@@ -1181,29 +1184,12 @@ class ExceptionTests(unittest.TestCase):
# The following line is included in the traceback report:
raise exc
- class BrokenExceptionDel:
- def __del__(self):
- exc = BrokenStrException()
- # The following line is included in the traceback report:
- raise exc
+ obj = BrokenDel()
+ with support.catch_unraisable_exception() as cm:
+ del obj
- for test_class in (BrokenDel, BrokenExceptionDel):
- with self.subTest(test_class):
- obj = test_class()
- with captured_stderr() as stderr:
- del obj
- report = stderr.getvalue()
- self.assertIn("Exception ignored", report)
- self.assertIn(test_class.__del__.__qualname__, report)
- self.assertIn("test_exceptions.py", report)
- self.assertIn("raise exc", report)
- if test_class is BrokenExceptionDel:
- self.assertIn("BrokenStrException", report)
- self.assertIn("<exception str() failed>", report)
- else:
- self.assertIn("ValueError", report)
- self.assertIn("del is broken", report)
- self.assertTrue(report.endswith("\n"))
+ self.assertEqual(cm.unraisable.object, BrokenDel.__del__)
+ self.assertIsNotNone(cm.unraisable.exc_traceback)
def test_unhandled(self):
# Check for sensible reporting of unhandled exceptions