Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tenacity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ def __exit__(
self.retry_state.set_result(None)
return None

async def __aenter__(self) -> None:
pass

async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: t.Optional["types.TracebackType"],
) -> bool | None:
return self.__exit__(exc_type, exc_value, traceback)


class BaseRetrying(ABC):
def __init__(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ async def test_do_max_attempts(self) -> None:

assert attempts == 3

@asynctest
async def test_async_with_attempt_manager(self) -> None:
"""AttemptManager supports async with for use inside async for."""
attempts = 0
retrying = tasyncio.AsyncRetrying(stop=stop_after_attempt(3))
try:
async for attempt in retrying:
async with attempt:
attempts += 1
raise Exception
except RetryError:
pass

assert attempts == 3

@asynctest
async def test_reraise(self) -> None:
class CustomError(Exception):
Expand Down
Loading