File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 55import pytest
66
77
8+ # stub for python 3.7 support
9+ class AsyncMock (mock .MagicMock ):
10+ def __init__ (self , * args , ** kwargs ):
11+ super (AsyncMock , self ).__init__ (* args , ** kwargs )
12+ self .__bool__ = lambda x : True
13+ async def __call__ (self , * args , ** kwargs ):
14+ return super (AsyncMock , self ).__call__ (* args , ** kwargs )
15+
16+
817async def sleep_task (* args ):
918 await asyncio .sleep (10 )
1019
1120
1221@pytest .mark .asyncio
1322async def test_cancel_callback_called ():
14- cancel_callback = mock .AsyncMock ()
23+ # can replace with mock.AsyncMock after python 3.7 support is dropped
24+ cancel_callback = AsyncMock ()
1525 with pytest .raises (asyncio .TimeoutError ):
26+ # timeout raises asyncio.CancelledError, and await_many_dispatch should
27+ # call cancel_callback
1628 async with async_timeout .timeout (0 ):
1729 await await_many_dispatch ([sleep_task ], sleep_task , cancel_callback )
1830 assert cancel_callback .called
You can’t perform that action at this time.
0 commit comments