Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mocking sleep when retrying async functions #440

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

snorfalorpagus
Copy link

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.

Copy link
Contributor

mergify bot commented Feb 8, 2024

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

jd
jd previously approved these changes Feb 9, 2024
@mergify mergify bot dismissed jd’s stale review February 9, 2024 13:32

Pull request has been modified.

@snorfalorpagus
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot easily mock out async sleep function
2 participants