File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 11import pytest
22from functools import wraps , partial
33import inspect
4+ import types
5+
6+
7+ @types .coroutine
8+ def mock_sleep ():
9+ yield "mock_sleep"
410
511
612# Wrap any 'async def' tests so that they get automatically iterated.
@@ -18,7 +24,12 @@ def pytest_pyfunc_call(pyfuncitem):
1824 def wrapper (** kwargs ):
1925 coro = fn (** kwargs )
2026 try :
21- coro .send (None )
27+ while True :
28+ value = coro .send (None )
29+ if value != "mock_sleep" : # pragma: no cover
30+ raise RuntimeError (
31+ "coroutine runner confused: {!r}" .format (value )
32+ )
2233 except StopIteration :
2334 pass
2435
Original file line number Diff line number Diff line change 22
33import types
44import sys
5- import asyncio
65import collections .abc
76from functools import wraps
87import gc
98
9+ from .conftest import mock_sleep
1010from .. import (
1111 async_generator ,
1212 yield_ ,
@@ -42,7 +42,7 @@ async def async_range(count):
4242async def double (ait ):
4343 async for value in ait :
4444 await yield_ (value * 2 )
45- await asyncio . sleep ( 0.001 )
45+ await mock_sleep ( )
4646
4747
4848class HasAsyncGenMethod :
@@ -194,18 +194,24 @@ async def recurse():
194194async def test_reentrance_forbidden_while_suspended_in_coroutine_runner ():
195195 @async_generator
196196 async def f ():
197- await asyncio . sleep ( 1 )
198- await yield_ ()
197+ await mock_sleep ( )
198+ await yield_ ("final yield" )
199199
200200 ag = f ()
201201 asend_coro = ag .asend (None )
202202 fut = asend_coro .send (None )
203+ assert fut == "mock_sleep"
203204 # Now the async generator's frame is not executing, but a call to asend()
204205 # *is* executing. Make sure that in this case, ag_running is True, and we
205206 # can't start up another call to asend().
206207 assert ag .ag_running
207208 with pytest .raises (ValueError ):
208209 await ag .asend (None )
210+ # Clean up
211+ with pytest .raises (StopIteration ):
212+ asend_coro .send (None )
213+ with pytest .raises (StopAsyncIteration ):
214+ ag .asend (None ).send (None )
209215
210216
211217################################################################
@@ -302,7 +308,7 @@ async def sync_yield_during_aclose():
302308 try :
303309 await yield_ (1 )
304310 finally :
305- await asyncio . sleep ( 0 )
311+ await mock_sleep ( )
306312
307313
308314@async_generator
You can’t perform that action at this time.
0 commit comments