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 1
1
import pytest
2
2
from functools import wraps , partial
3
3
import inspect
4
+ import types
5
+
6
+
7
+ @types .coroutine
8
+ def mock_sleep ():
9
+ yield "mock_sleep"
4
10
5
11
6
12
# Wrap any 'async def' tests so that they get automatically iterated.
@@ -18,7 +24,12 @@ def pytest_pyfunc_call(pyfuncitem):
18
24
def wrapper (** kwargs ):
19
25
coro = fn (** kwargs )
20
26
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
+ )
22
33
except StopIteration :
23
34
pass
24
35
Original file line number Diff line number Diff line change 2
2
3
3
import types
4
4
import sys
5
- import asyncio
6
5
import collections .abc
7
6
from functools import wraps
8
7
import gc
9
8
9
+ from .conftest import mock_sleep
10
10
from .. import (
11
11
async_generator ,
12
12
yield_ ,
@@ -42,7 +42,7 @@ async def async_range(count):
42
42
async def double (ait ):
43
43
async for value in ait :
44
44
await yield_ (value * 2 )
45
- await asyncio . sleep ( 0.001 )
45
+ await mock_sleep ( )
46
46
47
47
48
48
class HasAsyncGenMethod :
@@ -194,18 +194,24 @@ async def recurse():
194
194
async def test_reentrance_forbidden_while_suspended_in_coroutine_runner ():
195
195
@async_generator
196
196
async def f ():
197
- await asyncio . sleep ( 1 )
198
- await yield_ ()
197
+ await mock_sleep ( )
198
+ await yield_ ("final yield" )
199
199
200
200
ag = f ()
201
201
asend_coro = ag .asend (None )
202
202
fut = asend_coro .send (None )
203
+ assert fut == "mock_sleep"
203
204
# Now the async generator's frame is not executing, but a call to asend()
204
205
# *is* executing. Make sure that in this case, ag_running is True, and we
205
206
# can't start up another call to asend().
206
207
assert ag .ag_running
207
208
with pytest .raises (ValueError ):
208
209
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 )
209
215
210
216
211
217
################################################################
@@ -302,7 +308,7 @@ async def sync_yield_during_aclose():
302
308
try :
303
309
await yield_ (1 )
304
310
finally :
305
- await asyncio . sleep ( 0 )
311
+ await mock_sleep ( )
306
312
307
313
308
314
@async_generator
You can’t perform that action at this time.
0 commit comments