From: Tom Christie Date: Thu, 23 Jul 2020 09:40:00 +0000 (+0100) Subject: Parameterize invalid URL tests (#1079) X-Git-Tag: 0.14.0~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=696c1eff0390197358d8cb6807ab5de3a7c17fc0;p=thirdparty%2Fhttpx.git Parameterize invalid URL tests (#1079) --- diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index df2af917..f51c1df2 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -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") diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 3d72582b..4aae02c1 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -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):