tenacity
tenacity copied to clipboard
Add support for mocking sleep when retrying async functions
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.
⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.
@jd Let me know if there is anything else required before this can be merged. :)
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.