From 483849a466a2bfc121f5a367339e1aa3ed20344b Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Mon, 25 Dec 2023 13:03:09 +0330 Subject: [PATCH] Turn `scope["client"]` to `None` on `TestClient` (#2377) * Remove client scope from testclient * remove test * Update testclient.py --------- Co-authored-by: Marcelo Trylesinski --- starlette/testclient.py | 4 ++-- tests/test_testclient.py | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/starlette/testclient.py b/starlette/testclient.py index 04ac90a05..149fbb07a 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -245,7 +245,7 @@ def handle_request(self, request: httpx.Request) -> httpx.Response: "scheme": scheme, "query_string": query.encode(), "headers": headers, - "client": ["testclient", 50000], + "client": None, "server": [host, port], "subprotocols": subprotocols, "state": self.app_state.copy(), @@ -263,7 +263,7 @@ def handle_request(self, request: httpx.Request) -> httpx.Response: "scheme": scheme, "query_string": query.encode(), "headers": headers, - "client": ["testclient", 50000], + "client": None, "server": [host, port], "extensions": {"http.response.debug": {}}, "state": self.app_state.copy(), diff --git a/tests/test_testclient.py b/tests/test_testclient.py index 44bcd7ace..38c6f0872 100644 --- a/tests/test_testclient.py +++ b/tests/test_testclient.py @@ -254,19 +254,6 @@ async def asgi(receive, send): assert data == {"message": "test"} -def test_client(test_client_factory): - async def app(scope, receive, send): - client = scope.get("client") - assert client is not None - host, port = client - response = JSONResponse({"host": host, "port": port}) - await response(scope, receive, send) - - client = test_client_factory(app) - response = client.get("/") - assert response.json() == {"host": "testclient", "port": 50000} - - @pytest.mark.parametrize("param", ("2020-07-14T00:00:00+00:00", "España", "voilà")) def test_query_params(test_client_factory, param: str): def homepage(request):