From a7378f46773af3c8d80ceda40ae11fbfdef0f08c Mon Sep 17 00:00:00 2001 From: Ben Mezger Date: Mon, 9 Oct 2023 22:46:04 +0200 Subject: [PATCH] Ensure retry returns exception if functions returns it --- tests/test_retry.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_retry.py b/tests/test_retry.py index 5ead53b..0d16c60 100644 --- a/tests/test_retry.py +++ b/tests/test_retry.py @@ -261,6 +261,17 @@ async def _test(): await retry(strategies=[])(_test)() assert mock.call_count == 1 + @pytest.mark.asyncio + async def test_async_retry_returns_exception( + self, async_retry: t.Callable[..., AsyncRetry[t.Any]], async_func: AsyncMock + ) -> None: + async_func.return_value = ValueError + + retry = async_retry() + result = await retry(async_func) + + assert result == ValueError + class TestSyncRetry: @pytest.fixture @@ -484,3 +495,13 @@ def test_retry_state_repr(self): repr(state) == "RetryState(start_time=1, end_time=0, current_attempts=0, exception=ValueError('ABC')), returned_value=1)" ) + + def test_sync_retry_returns_exception( + self, sync_retry: t.Callable[..., Retry[t.Any]], func: MagicMock + ) -> None: + func.return_value = ValueError + + retry = sync_retry() + result = retry(func) + + assert result == ValueError