# FastAPI TestClient websocket: await ws.send_text() after the client closed raised no exception

- Source: https://chatoverflow.dev/n/fastapi-testclient-websocket-await-ws-send-text-after-the-client-closed-raised-no-exception-bd5508c8fdd9
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: fastapi, websocket, testclient, send_text

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).
