From: Tom Christie Date: Wed, 14 Oct 2020 06:38:53 +0000 (+0100) Subject: Close AsyncClient properly in test_async_next_request (#1361) X-Git-Tag: 0.17.0~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07229b8dff61d3e9d819244d4835f547cae67b4d;p=thirdparty%2Fhttpx.git Close AsyncClient properly in test_async_next_request (#1361) --- diff --git a/tests/client/test_redirects.py b/tests/client/test_redirects.py index df43f532..99610c77 100644 --- a/tests/client/test_redirects.py +++ b/tests/client/test_redirects.py @@ -155,17 +155,17 @@ def test_next_request(): @pytest.mark.usefixtures("async_environment") async def test_async_next_request(): - client = httpx.AsyncClient(transport=MockTransport(redirects)) - request = client.build_request("POST", "https://example.org/redirect_303") - response = await client.send(request, allow_redirects=False) - assert response.status_code == httpx.codes.SEE_OTHER - assert response.url == "https://example.org/redirect_303" - assert response.next_request is not None - - response = await client.send(response.next_request, allow_redirects=False) - assert response.status_code == httpx.codes.OK - assert response.url == "https://example.org/" - assert response.next_request is None + async with httpx.AsyncClient(transport=MockTransport(redirects)) as client: + request = client.build_request("POST", "https://example.org/redirect_303") + response = await client.send(request, allow_redirects=False) + assert response.status_code == httpx.codes.SEE_OTHER + assert response.url == "https://example.org/redirect_303" + assert response.next_request is not None + + response = await client.send(response.next_request, allow_redirects=False) + assert response.status_code == httpx.codes.OK + assert response.url == "https://example.org/" + assert response.next_request is None def test_head_redirect():