summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_coroutines.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-22 21:44:02 (GMT)
committerGitHub <noreply@github.com>2019-05-22 21:44:02 (GMT)
commite4d300e07c33a9a77549c62d8687d8fe130c53d5 (patch)
tree165c92b9c1ff6f78bbffbcb4c7d68979091fc061 /Lib/test/test_coroutines.py
parent904e34d4e6b6007986dcc585d5c553ee8ae06f95 (diff)
downloadcpython-e4d300e07c33a9a77549c62d8687d8fe130c53d5.zip
cpython-e4d300e07c33a9a77549c62d8687d8fe130c53d5.tar.gz
cpython-e4d300e07c33a9a77549c62d8687d8fe130c53d5.tar.bz2
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_coroutines.py')
-rw-r--r--Lib/test/test_coroutines.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 8443e65..036f13f 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -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: