]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Close AsyncClient properly in test_async_next_request (#1361)
authorTom Christie <tom@tomchristie.com>
Wed, 14 Oct 2020 06:38:53 +0000 (07:38 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Oct 2020 06:38:53 +0000 (08:38 +0200)
tests/client/test_redirects.py

index df43f532911a6fa3c83839f3de07c9d4f3290e6c..99610c771537e017da1e2481d9f5c8c93b08842f 100644 (file)
@@ -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():