Skip to content

Commit ff11ab3

Browse files
committed
Check err_msg in tests
1 parent 35bbe0e commit ff11ab3

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/test/test_coroutines.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,9 @@ async def func(): pass
21362136
coro = None
21372137
support.gc_collect()
21382138

2139+
self.assertEqual(cm.unraisable.err_msg,
2140+
f"Exception ignored while finalizing "
2141+
f"coroutine {coro_repr}")
21392142
self.assertIn("was never awaited", str(cm.unraisable.exc_value))
21402143

21412144
def test_for_assign_raising_stop_async_iteration(self):
@@ -2410,9 +2413,13 @@ async def corofn():
24102413
coro_repr = repr(coro)
24112414

24122415
# clear reference to the coroutine without awaiting for it
2416+
coro_repr = repr(coro)
24132417
del coro
24142418
support.gc_collect()
24152419

2420+
self.assertEqual(cm.unraisable.err_msg,
2421+
f"Exception ignored while finalizing "
2422+
f"coroutine {coro_repr}")
24162423
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
24172424

24182425
del warnings._warn_unawaited_coroutine

Lib/test/test_exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,9 +1678,13 @@ def __del__(self):
16781678

16791679
obj = BrokenDel()
16801680
with support.catch_unraisable_exception() as cm:
1681+
obj_repr = repr(type(obj).__del__)
16811682
del obj
16821683

16831684
gc_collect() # For PyPy or other GCs.
1685+
self.assertEqual(cm.unraisable.err_msg,
1686+
f"Exception ignored while calling "
1687+
f"deallocator {obj_repr}")
16841688
self.assertIsNotNone(cm.unraisable.exc_traceback)
16851689

16861690
def test_unhandled(self):

Lib/test/test_generators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,14 +2664,17 @@ def printsolution(self, x):
26642664
>>> with support.catch_unraisable_exception() as cm:
26652665
... g = f()
26662666
... next(g)
2667+
... gen_repr = repr(g)
26672668
... del g
26682669
...
2670+
... cm.unraisable.err_msg == f'Exception ignored while closing generator {gen_repr}'
26692671
... cm.unraisable.exc_type == RuntimeError
26702672
... "generator ignored GeneratorExit" in str(cm.unraisable.exc_value)
26712673
... cm.unraisable.exc_traceback is not None
26722674
True
26732675
True
26742676
True
2677+
True
26752678
26762679
And errors thrown during closing should propagate:
26772680

0 commit comments

Comments
 (0)