I am trying to test a websocket endpoint that uses websocket.recv() inside, but this method is throwing an exception.
Error
ERROR sanic.error:handlers.py:183 Exception occurred while handling uri: 'http:///ws'
Traceback (most recent call last):
File "/worker/.local/lib/python3.7/site-packages/sanic/app.py", line 971, in _websocket_handler
await fut
File "/app/application_tests/test_sanic_testing.py", line 18, in handler
await ws.recv()
File "/worker/.local/lib/python3.7/site-packages/sanic/server/websockets/connection.py", line 49, in recv
if message["type"] == "websocket.receive":
KeyError: 'type'
I am trying to test a websocket endpoint that uses
websocket.recv()
inside, but this method is throwing an exception.Error
How to reproduce
from sanic_testing import TestManager
@pytest.fixture def app(): sanic_app = Sanic("test") TestManager(sanic_app) return sanic_app
@pytest.mark.asyncio async def test_websocket_route(app): @app.websocket("/ws") async def handler(request, ws): await ws.recv()
pytest-asyncio==0.19.0 sanic==22.6.1 sanic-testing==22.6.0