Skip to content

Commit 8535a21

Browse files
committed
Manually iterate coroutines to avoid asyncio use
1 parent 9b3ba13 commit 8535a21

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Lib/test/test_contextlib.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Unit tests for contextlib.py, and other context managers."""
2-
import asyncio
32
import io
43
import os
54
import sys
@@ -713,7 +712,10 @@ async def test(x):
713712
self.assertEqual(state, [1])
714713
state.append(x)
715714

716-
asyncio.run(test('something'))
715+
coro = test('something')
716+
with self.assertRaises(StopIteration):
717+
coro.send(None)
718+
717719
self.assertEqual(state, [1, 'something', 999])
718720

719721

@@ -736,7 +738,12 @@ async def run_test():
736738
async for _ in test("something"):
737739
self.assertEqual(state, [1, "something"])
738740

739-
asyncio.run(run_test())
741+
agen = test('something')
742+
with self.assertRaises(StopIteration):
743+
agen.asend(None).send(None)
744+
with self.assertRaises(StopAsyncIteration):
745+
agen.asend(None).send(None)
746+
740747
self.assertEqual(state, [1, 'something', "second item", 999])
741748

742749

0 commit comments

Comments
 (0)