1010import tracemalloc
1111from typing import Any , Union , cast
1212from unittest import mock
13+ from typing_extensions import Literal
1314
1415import httpx
1516import pytest
@@ -727,7 +728,14 @@ def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> Non
727728 @pytest .mark .parametrize ("failures_before_success" , [0 , 2 , 4 ])
728729 @mock .patch ("asktable._base_client.BaseClient._calculate_retry_timeout" , _low_retry_timeout )
729730 @pytest .mark .respx (base_url = base_url )
730- def test_retries_taken (self , client : Asktable , failures_before_success : int , respx_mock : MockRouter ) -> None :
731+ @pytest .mark .parametrize ("failure_mode" , ["status" , "exception" ])
732+ def test_retries_taken (
733+ self ,
734+ client : Asktable ,
735+ failures_before_success : int ,
736+ failure_mode : Literal ["status" , "exception" ],
737+ respx_mock : MockRouter ,
738+ ) -> None :
731739 client = client .with_options (max_retries = 4 )
732740
733741 nb_retries = 0
@@ -736,6 +744,8 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
736744 nonlocal nb_retries
737745 if nb_retries < failures_before_success :
738746 nb_retries += 1
747+ if failure_mode == "exception" :
748+ raise RuntimeError ("oops" )
739749 return httpx .Response (500 )
740750 return httpx .Response (200 )
741751
@@ -1489,8 +1499,13 @@ async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter)
14891499 @mock .patch ("asktable._base_client.BaseClient._calculate_retry_timeout" , _low_retry_timeout )
14901500 @pytest .mark .respx (base_url = base_url )
14911501 @pytest .mark .asyncio
1502+ @pytest .mark .parametrize ("failure_mode" , ["status" , "exception" ])
14921503 async def test_retries_taken (
1493- self , async_client : AsyncAsktable , failures_before_success : int , respx_mock : MockRouter
1504+ self ,
1505+ async_client : AsyncAsktable ,
1506+ failures_before_success : int ,
1507+ failure_mode : Literal ["status" , "exception" ],
1508+ respx_mock : MockRouter ,
14941509 ) -> None :
14951510 client = async_client .with_options (max_retries = 4 )
14961511
@@ -1500,6 +1515,8 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
15001515 nonlocal nb_retries
15011516 if nb_retries < failures_before_success :
15021517 nb_retries += 1
1518+ if failure_mode == "exception" :
1519+ raise RuntimeError ("oops" )
15031520 return httpx .Response (500 )
15041521 return httpx .Response (200 )
15051522
0 commit comments