MCPcopy
hub / github.com/encode/starlette / test_client_close

Function test_client_close

tests/test_websockets.py:241–259  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

239
240
241def test_client_close(test_client_factory: TestClientFactory) -> None:
242 close_code = None
243 close_reason = None
244
245 async def app(scope: Scope, receive: Receive, send: Send) -> None:
246 nonlocal close_code, close_reason
247 websocket = WebSocket(scope, receive=receive, send=send)
248 await websocket.accept()
249 try:
250 await websocket.receive_text()
251 except WebSocketDisconnect as exc:
252 close_code = exc.code
253 close_reason = exc.reason
254
255 client = test_client_factory(app)
256 with client.websocket_connect("/") as websocket:
257 websocket.close(code=status.WS_1001_GOING_AWAY, reason="Going Away")
258 assert close_code == status.WS_1001_GOING_AWAY
259 assert close_reason == "Going Away"
260
261
262@pytest.mark.anyio

Callers

nothing calls this directly

Calls 3

closeMethod · 0.95
test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80

Tested by

no test coverage detected