Skip to content

Commit c691752

Browse files
committed
Add unit test for cancel_callback
1 parent d7c96e2 commit c691752

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_utils.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from channels.utils import await_many_dispatch
2+
import asyncio
3+
import async_timeout
4+
from unittest import mock
5+
import pytest
6+
7+
async def sleep_task(*args):
8+
await asyncio.sleep(10)
9+
10+
@pytest.mark.asyncio
11+
async def test_cancel_callback_called():
12+
cancel_callback = mock.AsyncMock()
13+
with pytest.raises(asyncio.TimeoutError):
14+
async with async_timeout.timeout(0):
15+
await await_many_dispatch([sleep_task], sleep_task, cancel_callback)
16+
print(cancel_callback.__dict__)
17+
assert cancel_callback.called

0 commit comments

Comments
 (0)