mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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.
This commit is contained in:
parent
904e34d4e6
commit
e4d300e07c
6 changed files with 108 additions and 43 deletions
|
@ -2342,12 +2342,19 @@ class OriginTrackingTest(unittest.TestCase):
|
|||
orig_wuc = warnings._warn_unawaited_coroutine
|
||||
try:
|
||||
warnings._warn_unawaited_coroutine = lambda coro: 1/0
|
||||
with support.captured_stderr() as stream:
|
||||
corofn()
|
||||
with support.catch_unraisable_exception() as cm, \
|
||||
support.captured_stderr() as stream:
|
||||
# only store repr() to avoid keeping the coroutine alive
|
||||
coro = corofn()
|
||||
coro_repr = repr(coro)
|
||||
|
||||
# clear reference to the coroutine without awaiting for it
|
||||
del coro
|
||||
support.gc_collect()
|
||||
self.assertIn("Exception ignored in", stream.getvalue())
|
||||
self.assertIn("ZeroDivisionError", stream.getvalue())
|
||||
self.assertIn("was never awaited", stream.getvalue())
|
||||
|
||||
self.assertEqual(repr(cm.unraisable.object), coro_repr)
|
||||
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
|
||||
self.assertIn("was never awaited", stream.getvalue())
|
||||
|
||||
del warnings._warn_unawaited_coroutine
|
||||
with support.captured_stderr() as stream:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue