File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 5
5
import pytest
6
6
7
7
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
+
8
17
async def sleep_task (* args ):
9
18
await asyncio .sleep (10 )
10
19
11
20
12
21
@pytest .mark .asyncio
13
22
async 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 ()
15
25
with pytest .raises (asyncio .TimeoutError ):
26
+ # timeout raises asyncio.CancelledError, and await_many_dispatch should
27
+ # call cancel_callback
16
28
async with async_timeout .timeout (0 ):
17
29
await await_many_dispatch ([sleep_task ], sleep_task , cancel_callback )
18
30
assert cancel_callback .called
You can’t perform that action at this time.
0 commit comments