Skip to content

Commit 2b33f2a

Browse files
pcriadoperezPablo
andauthored
fix: fix test for 3.12 (sammchardy#1518)
Co-authored-by: Pablo <pablo@Pablos-MacBook-Pro.local>
1 parent b26aa11 commit 2b33f2a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ python_binance.egg-info/
99
*.egg-info/
1010
.idea/
1111
venv*/
12+
.vscode

tests/test_reconnecting_websocket.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from binance.exceptions import BinanceWebsocketUnableToConnect
99
from websockets import WebSocketClientProtocol # type: ignore
1010
from websockets.protocol import State
11+
import asyncio
1112

1213
try:
1314
from unittest.mock import AsyncMock # Python 3.8+
@@ -175,7 +176,7 @@ async def test_connect_fails_to_connect_on_enter_context():
175176
async def test_connect_fails_to_connect_after_disconnect():
176177
# Create mock WebSocket client
177178
mock_socket = create_autospec(WebSocketClientProtocol)
178-
mock_socket.recv = AsyncMock(return_value='{"e": "value"}')
179+
mock_socket.recv = AsyncMock(side_effect=delayed_return)
179180
mock_socket.state = AsyncMock()
180181

181182
# Create mock connect that succeeds first, then fails
@@ -200,3 +201,8 @@ async def test_connect_fails_to_connect_after_disconnect():
200201
# After retrying to reconnect, receive BinanceWebsocketUnableToConnect
201202
assert msg["e"] == "error"
202203
assert msg["type"] == "BinanceWebsocketUnableToConnect"
204+
205+
206+
async def delayed_return():
207+
await asyncio.sleep(0.1) # 100 ms delay
208+
return '{"e": "value"}'

0 commit comments

Comments
 (0)