tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Add support for mocking sleep when retrying async functions

Open snorfalorpagus opened this issue 2 years ago • 4 comments

This PR makes it easier to mock sleeping when retrying asynchronous functions, using the same approach as was done for synchronous functions in #236.

Example usage:

@retry(wait=wait_fixed(9999999))
def function_with_retry():
    if random.random() < 0.9:
        raise RuntimeError("boom")
    return True

async def test_something(self):
    with unittest.mock.patch("tenacity.nap.asyncio_sleep", AsyncMock()):
        await function_with_retry()

Closes #360.

snorfalorpagus avatar Feb 08 '24 23:02 snorfalorpagus

⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.

mergify[bot] avatar Feb 08 '24 23:02 mergify[bot]

@jd Let me know if there is anything else required before this can be merged. :)

snorfalorpagus avatar Mar 01 '24 09:03 snorfalorpagus

It would be nice to see this get in soon. We monkeypatch the sleep property on the retry decorator in our tests, however that approach broke in 8.4.2.

aaronkavlie-wf avatar Jun 24 '24 22:06 aaronkavlie-wf