@@ -353,8 +353,7 @@ def _run_test_method(self, method):
353
353
if asyncio .iscoroutine (result ):
354
354
self .loop .run_until_complete (result )
355
355
356
- @asyncio .coroutine
357
- def doCleanups (self ):
356
+ async def doCleanups (self ):
358
357
"""
359
358
Execute all cleanup functions. Normally called for you after tearDown.
360
359
"""
@@ -363,7 +362,7 @@ def doCleanups(self):
363
362
function , args , kwargs = self ._cleanups .pop ()
364
363
with outcome .testPartExecutor (self ):
365
364
if asyncio .iscoroutinefunction (function ):
366
- yield from function (* args , ** kwargs )
365
+ await function (* args , ** kwargs )
367
366
else :
368
367
function (* args , ** kwargs )
369
368
@@ -377,8 +376,7 @@ def addCleanup(self, function, *args, **kwargs):
377
376
"""
378
377
return super ().addCleanup (function , * args , ** kwargs )
379
378
380
- @asyncio .coroutine
381
- def assertAsyncRaises (self , exception , awaitable ):
379
+ async def assertAsyncRaises (self , exception , awaitable ):
382
380
"""
383
381
Test that an exception of type ``exception`` is raised when an
384
382
exception is raised when awaiting ``awaitable``, a future or coroutine.
@@ -391,40 +389,37 @@ def assertAsyncRaises(self, exception, awaitable):
391
389
:see: :meth:`unittest.TestCase.assertRaises()`
392
390
"""
393
391
with self .assertRaises (exception ):
394
- return ( yield from awaitable )
392
+ return await awaitable
395
393
396
- @asyncio .coroutine
397
- def assertAsyncRaisesRegex (self , exception , regex , awaitable ):
394
+ async def assertAsyncRaisesRegex (self , exception , regex , awaitable ):
398
395
"""
399
396
Like :meth:`assertAsyncRaises()` but also tests that ``regex`` matches
400
397
on the string representation of the raised exception.
401
398
402
399
:see: :meth:`unittest.TestCase.assertRaisesRegex()`
403
400
"""
404
401
with self .assertRaisesRegex (exception , regex ):
405
- return ( yield from awaitable )
402
+ return await awaitable
406
403
407
- @asyncio .coroutine
408
- def assertAsyncWarns (self , warning , awaitable ):
404
+ async def assertAsyncWarns (self , warning , awaitable ):
409
405
"""
410
406
Test that a warning is triggered when awaiting ``awaitable``, a future
411
407
or a coroutine.
412
408
413
409
:see: :meth:`unittest.TestCase.assertWarns()`
414
410
"""
415
411
with self .assertWarns (warning ):
416
- return ( yield from awaitable )
412
+ return await awaitable
417
413
418
- @asyncio .coroutine
419
- def assertAsyncWarnsRegex (self , warning , regex , awaitable ):
414
+ async def assertAsyncWarnsRegex (self , warning , regex , awaitable ):
420
415
"""
421
416
Like :meth:`assertAsyncWarns()` but also tests that ``regex`` matches
422
417
on the message of the triggered warning.
423
418
424
419
:see: :meth:`unittest.TestCase.assertWarnsRegex()`
425
420
"""
426
421
with self .assertWarnsRegex (warning , regex ):
427
- return ( yield from awaitable )
422
+ return await awaitable
428
423
429
424
430
425
class FunctionTestCase (TestCase , unittest .FunctionTestCase ):
@@ -446,8 +441,7 @@ def _init_loop(self):
446
441
self .loop .time = functools .wraps (self .loop .time )(lambda : self ._time )
447
442
self ._time = 0
448
443
449
- @asyncio .coroutine
450
- def advance (self , seconds ):
444
+ async def advance (self , seconds ):
451
445
"""
452
446
Fast forward time by a number of ``seconds``.
453
447
@@ -468,7 +462,7 @@ def advance(self, seconds):
468
462
raise ValueError (
469
463
'Cannot go back in time ({} seconds)' .format (seconds ))
470
464
471
- yield from self ._drain_loop ()
465
+ await self ._drain_loop ()
472
466
473
467
target_time = self ._time + seconds
474
468
while True :
@@ -477,26 +471,25 @@ def advance(self, seconds):
477
471
break
478
472
479
473
self ._time = next_time
480
- yield from self ._drain_loop ()
474
+ await self ._drain_loop ()
481
475
482
476
self ._time = target_time
483
- yield from self ._drain_loop ()
477
+ await self ._drain_loop ()
484
478
485
479
def _next_scheduled (self ):
486
480
try :
487
481
return self .loop ._scheduled [0 ]._when
488
482
except IndexError :
489
483
return None
490
484
491
- @asyncio .coroutine
492
- def _drain_loop (self ):
485
+ async def _drain_loop (self ):
493
486
while True :
494
487
next_time = self ._next_scheduled ()
495
488
if not self .loop ._ready and (next_time is None or
496
489
next_time > self ._time ):
497
490
break
498
491
499
- yield from asyncio .sleep (0 )
492
+ await asyncio .sleep (0 )
500
493
self .loop ._TestCase_asynctest_ran = True
501
494
502
495
0 commit comments