Open hollandjake opened 2 years ago
Example test to show failure
@pytest.mark.asyncio
async def test():
app = FastAPI()
@app.websocket("/ws")
async def ws(websocket: WebSocket):
await websocket.close() # Reject the connection
async with TestClient(app) as client:
async with client.websocket_connect("/ws") as ws:
pass
Hello all ! Any update on this issue (and merge request linked) ? Will be useful for me too 😄
Merge request LGTM but can't do anything
In the scenario where a websocket connection is closed before being accepted by the server, the WebSocketSession currently throws an
AssertionError
due to the received message not being type"websocket.accept"
(see assertion)If a connection request is cancelled before being accepted it should raise the message in someway so tests can process the response.
This should also apply to any message being received first that isn't an accept type since any of these would be a failure of the websocket protocol