Skip to content

Commit

Permalink
Adopted unittest.mock.AsyncMock in async unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 24, 2024
1 parent abf336e commit 8f0e66c
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 567 deletions.
12 changes: 0 additions & 12 deletions tests/async/helpers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import asyncio
from unittest import mock


def AsyncMock(*args, **kwargs):
"""Return a mock asynchronous function."""
m = mock.MagicMock(*args, **kwargs)

async def mock_coro(*args, **kwargs):
return m(*args, **kwargs)

mock_coro.mock = m
return mock_coro


def _run(coro):
Expand Down
3 changes: 1 addition & 2 deletions tests/async/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import socketio
from socketio.exceptions import ConnectionError
from tests.asyncio_web_server import SocketIOWebServer
from .helpers import AsyncMock


def with_instrumented_server(auth=False, **ikwargs):
Expand Down Expand Up @@ -211,7 +210,7 @@ def test_admin_connect_with_others(self):
sid1 = client1.sid

saved_check_for_upgrade = self.isvr._check_for_upgrade
self.isvr._check_for_upgrade = AsyncMock()
self.isvr._check_for_upgrade = mock.AsyncMock()
client2.connect('http://localhost:8900', namespace='/foo',
transports=['polling'])
sid2 = client2.sid
Expand Down
Loading

0 comments on commit 8f0e66c

Please sign in to comment.