Skip to content

Commit 5358c1e

Browse files
committed
make 3.7 work
1 parent 68c63fa commit 5358c1e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/test_utils.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@
55
import 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+
817
async def sleep_task(*args):
918
await asyncio.sleep(10)
1019

1120

1221
@pytest.mark.asyncio
1322
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()
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

0 commit comments

Comments
 (0)