3939
4040def coroutine_test (event_loop , transaction , nr_enabled = True , does_hang = False , call_exit = False , runtime_error = False ):
4141 @transaction
42- @asyncio .coroutine
43- def task ():
42+ async def task ():
4443 txn = current_transaction ()
4544
4645 if not nr_enabled :
@@ -55,15 +54,15 @@ def task():
5554
5655 try :
5756 if does_hang :
58- yield from loop .create_future ()
57+ await loop .create_future () # noqa
5958 else :
60- yield from asyncio .sleep (0.0 )
59+ await asyncio .sleep (0.0 )
6160 if nr_enabled and txn .enabled :
6261 # Validate loop time is recorded after suspend
6362 assert txn ._loop_time > 0.0
6463 except GeneratorExit :
6564 if runtime_error :
66- yield from asyncio .sleep (0.0 )
65+ await asyncio .sleep (0.0 )
6766
6867 return task
6968
@@ -160,11 +159,10 @@ def test_async_coroutine_throw_cancel(event_loop, num_coroutines, create_test_ta
160159
161160 tasks = [create_test_task (event_loop , transaction ) for _ in range (num_coroutines )]
162161
163- @asyncio .coroutine
164- def task_c ():
162+ async def task_c ():
165163 futures = [asyncio .ensure_future (t ()) for t in tasks ]
166164
167- yield from asyncio .sleep (0.0 )
165+ await asyncio .sleep (0.0 )
168166
169167 [f .cancel () for f in futures ]
170168
@@ -195,8 +193,7 @@ def test_async_coroutine_throw_error(event_loop, num_coroutines, create_test_tas
195193
196194 tasks = [create_test_task (event_loop , transaction ) for _ in range (num_coroutines )]
197195
198- @asyncio .coroutine
199- def task_c ():
196+ async def task_c ():
200197 coros = [t () for t in tasks ]
201198
202199 for coro in coros :
@@ -232,14 +229,13 @@ def test_async_coroutine_close(event_loop, num_coroutines, create_test_task, tra
232229
233230 tasks = [create_test_task (event_loop , transaction ) for _ in range (num_coroutines )]
234231
235- @asyncio .coroutine
236- def task_c ():
232+ async def task_c ():
237233 coros = [t () for t in tasks ]
238234
239235 if start_coroutines :
240236 [asyncio .ensure_future (coro ) for coro in coros ]
241237
242- yield from asyncio .sleep (0.0 )
238+ await asyncio .sleep (0.0 )
243239
244240 [coro .close () for coro in coros ]
245241
@@ -273,13 +269,12 @@ def test_async_coroutine_close_raises_error(event_loop, num_coroutines, create_t
273269
274270 tasks = [create_test_task (event_loop , transaction , runtime_error = True ) for _ in range (num_coroutines )]
275271
276- @asyncio .coroutine
277- def task_c ():
272+ async def task_c ():
278273 coros = [t () for t in tasks ]
279274
280275 [c .send (None ) for c in coros ]
281276
282- yield from asyncio .sleep (0.0 )
277+ await asyncio .sleep (0.0 )
283278
284279 for coro in coros :
285280 with pytest .raises (RuntimeError ):
@@ -313,24 +308,21 @@ def test_deferred_async_background_task(event_loop, transaction, metric, argumen
313308 args , kwargs = arguments ("deferred" )
314309
315310 @transaction (* args , ** kwargs )
316- @asyncio .coroutine
317- def child_task ():
318- yield from asyncio .sleep (0 )
311+ async def child_task ():
312+ await asyncio .sleep (0 )
319313
320314 main_metric = (metric % "main" , "" )
321315
322316 args , kwargs = arguments ("main" )
323317
324318 @transaction (* args , ** kwargs )
325- @asyncio .coroutine
326- def parent_task ():
327- yield from asyncio .sleep (0 )
319+ async def parent_task ():
320+ await asyncio .sleep (0 )
328321 return event_loop .create_task (child_task ())
329322
330- @asyncio .coroutine
331- def test_runner ():
332- child = yield from parent_task ()
333- yield from child
323+ async def test_runner ():
324+ child = await parent_task ()
325+ await child
334326
335327 metrics = []
336328
@@ -362,18 +354,16 @@ def test_child_transaction_when_parent_is_running(event_loop, transaction, metri
362354 args , kwargs = arguments ("deferred" )
363355
364356 @transaction (* args , ** kwargs )
365- @asyncio .coroutine
366- def child_task ():
367- yield from asyncio .sleep (0 )
357+ async def child_task ():
358+ await asyncio .sleep (0 )
368359
369360 main_metric = (metric % "main" , "" )
370361
371362 args , kwargs = arguments ("main" )
372363
373364 @transaction (* args , ** kwargs )
374- @asyncio .coroutine
375- def parent_task ():
376- yield from event_loop .create_task (child_task ())
365+ async def parent_task ():
366+ await event_loop .create_task (child_task ())
377367
378368 metrics = []
379369
@@ -405,9 +395,8 @@ def test_nested_coroutine_inside_sync(event_loop, transaction, metric, arguments
405395 args , kwargs = arguments ("child" )
406396
407397 @transaction (* args , ** kwargs )
408- @asyncio .coroutine
409- def child_task ():
410- yield from asyncio .sleep (0 )
398+ async def child_task ():
399+ await asyncio .sleep (0 )
411400
412401 main_metric = (metric % "main" , "" )
413402 args , kwargs = arguments ("main" )
@@ -443,22 +432,20 @@ def test_nested_coroutine_task_already_active(event_loop, transaction, metric, a
443432 args , kwargs = arguments ("deferred" )
444433
445434 @transaction (* args , ** kwargs )
446- @asyncio .coroutine
447- def child_task ():
448- yield from asyncio .sleep (0 )
435+ async def child_task ():
436+ await asyncio .sleep (0 )
449437
450438 @function_trace ()
451- def child_trace ():
452- yield from child_task ()
439+ async def child_trace ():
440+ await child_task ()
453441
454442 main_metric = (metric % "main" , "" )
455443
456444 args , kwargs = arguments ("main" )
457445
458446 @transaction (* args , ** kwargs )
459- @asyncio .coroutine
460- def parent_task ():
461- yield from event_loop .create_task (child_trace ())
447+ async def parent_task ():
448+ await event_loop .create_task (child_trace ())
462449
463450 metrics = []
464451
0 commit comments