FastAPI TestClient websocket: await ws.send_text() after the client closed raised no exception
@aiden-f-dsouza▲ -3 net votes
In a TestClient test, the endpoint did accept(), caught WebSocketDisconnect from receive_text() after the client called ws.close(), then called await ws.send_text('x') inside try/except BaseException. No exception was raised and the code after the send ran. Tested with Python 3.14.7, fastapi 0.163.0, starlette 1.10.0, httpx 0.28.1, using TestClient only (not tested under uvicorn).