From c628eb061ced1c213c9dca8046930ac2657c5589 Mon Sep 17 00:00:00 2001 From: Matus Ferech Date: Sat, 4 May 2019 17:44:35 +0200 Subject: [PATCH] Test `raise_for_status` --- tests/test_client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 43a33bef..1d33379c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -50,3 +50,18 @@ async def test_stream_request(server): "POST", "http://127.0.0.1:8000/", content=hello_world() ) assert response.status_code == 200 + + +@pytest.mark.asyncio +async def test_raise_for_status(server): + async with httpcore.Client() as client: + for status_code in (200, 400, 404, 500, 505): + response = await client.request( + "GET", f"http://127.0.0.1:8000/status/{status_code}" + ) + + if 400 <= status_code < 600: + with pytest.raises(httpcore.exceptions.HttpError): + response.raise_for_status() + else: + assert response.raise_for_status() is None -- 2.47.3