]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Make all the tests from test_queryparams to be async
authorKar Petrosyan <kar.petrosyanpy@gmail.com>
Thu, 27 Feb 2025 15:23:00 +0000 (19:23 +0400)
committerKar Petrosyan <kar.petrosyanpy@gmail.com>
Thu, 27 Feb 2025 15:23:00 +0000 (19:23 +0400)
tests/client/test_queryparams.py

index e5acb0ba20b39182b841f9549467d7b2012ac064..52833f11d486c205f7a7c388abc4b2b8a503467d 100644 (file)
@@ -1,3 +1,5 @@
+import pytest
+
 import httpx
 
 
@@ -5,31 +7,36 @@ def hello_world(request: httpx.Request) -> httpx.Response:
     return httpx.Response(200, text="Hello, world")
 
 
-def test_client_queryparams():
+@pytest.mark.anyio
+async def test_client_queryparams():
     client = httpx.Client(params={"a": "b"})
     assert isinstance(client.params, httpx.QueryParams)
     assert client.params["a"] == "b"
 
 
-def test_client_queryparams_string():
-    client = httpx.Client(params="a=b")
-    assert isinstance(client.params, httpx.QueryParams)
-    assert client.params["a"] == "b"
+@pytest.mark.anyio
+async def test_client_queryparams_string():
+    async with httpx.AsyncClient(params="a=b") as client:
+        assert isinstance(client.params, httpx.QueryParams)
+        assert client.params["a"] == "b"
 
-    client = httpx.Client()
-    client.params = "a=b"  # type: ignore
-    assert isinstance(client.params, httpx.QueryParams)
-    assert client.params["a"] == "b"
+    async with httpx.AsyncClient() as client:
+        client.params = "a=b"  # type: ignore
+        assert isinstance(client.params, httpx.QueryParams)
+        assert client.params["a"] == "b"
 
 
-def test_client_queryparams_echo():
+@pytest.mark.anyio
+async def test_client_queryparams_echo():
     url = "http://example.org/echo_queryparams"
     client_queryparams = "first=str"
     request_queryparams = {"second": "dict"}
-    client = httpx.Client(
+    async with httpx.AsyncClient(
         transport=httpx.MockTransport(hello_world), params=client_queryparams
-    )
-    response = client.get(url, params=request_queryparams)
+    ) as client:
+        response = await client.get(url, params=request_queryparams)
 
-    assert response.status_code == 200
-    assert response.url == "http://example.org/echo_queryparams?first=str&second=dict"
+        assert response.status_code == 200
+        assert (
+            response.url == "http://example.org/echo_queryparams?first=str&second=dict"
+        )