Skip to content

Commit

Permalink
Ensure retry returns exception if functions returns it
Browse files Browse the repository at this point in the history
  • Loading branch information
benmezger committed Oct 9, 2023
1 parent e7c792a commit a7378f4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit a7378f4

Please sign in to comment.