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

Documentation on mocking ratelimit limits decorator #34

Open
mcohoon opened this issue May 8, 2019 · 2 comments
Open

Documentation on mocking ratelimit limits decorator #34

mcohoon opened this issue May 8, 2019 · 2 comments

Comments

@mcohoon
Copy link

mcohoon commented May 8, 2019

I've implemented rate limiting as documented in the readme:

@on_exception(expo, RateLimitException, max_tries=8)
@limits(calls=15, period=FIFTEEN_MINUTES)
def call_api(url):
    response = requests.get(url)
    ...

But I would like a way to effectively turn off this rate-limiting while running tests. I've not found any concise examples on stackoverflow on how mock a decorator as such without re-importing the module, and I think this would be an ideal library to show how to mock out a decorator for testing. Would you be open to adding an example of how to do such a thing?

@stuaxo
Copy link

stuaxo commented Feb 13, 2020

Having an API to reset the rate limit would be enough for me, since I could call it in the unittest.

@stuaxo
Copy link

stuaxo commented Feb 21, 2020

Hi @mcohoon @tom-james-watson I've implemented this in the PR #43 Add reset_ratelimit method.

I spent a lot of time trying to workaround this, but it was just too difficult without being able to reset the limit.

In my test I used this along with fakesleep and am able to test my function that is decorated with sleep_and_retry and limits

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

No branches or pull requests

2 participants