]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Parameterize invalid URL tests (#1079)
authorTom Christie <tom@tomchristie.com>
Thu, 23 Jul 2020 09:40:00 +0000 (10:40 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Jul 2020 09:40:00 +0000 (10:40 +0100)
tests/client/test_async_client.py
tests/client/test_client.py

index df2af9178ae4ae8b26649e638b99f146fc36f0ac..f51c1df2816d9ea2e396882d1f63c4cb76fea305 100644 (file)
@@ -18,15 +18,19 @@ async def test_get(server):
     assert response.elapsed > timedelta(seconds=0)
 
 
+@pytest.mark.parametrize(
+    "url",
+    [
+        pytest.param("invalid://example.org", id="scheme-not-http(s)"),
+        pytest.param("://example.org", id="no-scheme"),
+        pytest.param("http://", id="no-host"),
+    ],
+)
 @pytest.mark.usefixtures("async_environment")
-async def test_get_invalid_url(server):
+async def test_get_invalid_url(server, url):
     async with httpx.AsyncClient() as client:
         with pytest.raises(httpx.InvalidURL):
-            await client.get("invalid://example.org")
-        with pytest.raises(httpx.InvalidURL):
-            await client.get("://example.org")
-        with pytest.raises(httpx.InvalidURL):
-            await client.get("http://")
+            await client.get(url)
 
 
 @pytest.mark.usefixtures("async_environment")
index 3d72582b08b3edba9b29a6cf7dc1762d317ba113..4aae02c1b7fad91c69e9c187cafd7ea200186903 100644 (file)
@@ -22,14 +22,18 @@ def test_get(server):
     assert response.elapsed > timedelta(0)
 
 
-def test_get_invalid_url(server):
+@pytest.mark.parametrize(
+    "url",
+    [
+        pytest.param("invalid://example.org", id="scheme-not-http(s)"),
+        pytest.param("://example.org", id="no-scheme"),
+        pytest.param("http://", id="no-host"),
+    ],
+)
+def test_get_invalid_url(server, url):
     with httpx.Client() as client:
         with pytest.raises(httpx.InvalidURL):
-            client.get("invalid://example.org")
-        with pytest.raises(httpx.InvalidURL):
-            client.get("://example.org")
-        with pytest.raises(httpx.InvalidURL):
-            client.get("http://")
+            client.get(url)
 
 
 def test_build_request(server):