Skip to content

Commit 8f0e66c

Browse files
Adopted unittest.mock.AsyncMock in async unit tests
1 parent abf336e commit 8f0e66c

8 files changed

+543
-567
lines changed

tests/async/helpers.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
import asyncio
2-
from unittest import mock
3-
4-
5-
def AsyncMock(*args, **kwargs):
6-
"""Return a mock asynchronous function."""
7-
m = mock.MagicMock(*args, **kwargs)
8-
9-
async def mock_coro(*args, **kwargs):
10-
return m(*args, **kwargs)
11-
12-
mock_coro.mock = m
13-
return mock_coro
142

153

164
def _run(coro):

tests/async/test_admin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import socketio
1111
from socketio.exceptions import ConnectionError
1212
from tests.asyncio_web_server import SocketIOWebServer
13-
from .helpers import AsyncMock
1413

1514

1615
def with_instrumented_server(auth=False, **ikwargs):
@@ -211,7 +210,7 @@ def test_admin_connect_with_others(self):
211210
sid1 = client1.sid
212211

213212
saved_check_for_upgrade = self.isvr._check_for_upgrade
214-
self.isvr._check_for_upgrade = AsyncMock()
213+
self.isvr._check_for_upgrade = mock.AsyncMock()
215214
client2.connect('http://localhost:8900', namespace='/foo',
216215
transports=['polling'])
217216
sid2 = client2.sid

0 commit comments

Comments
 (0)