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

Bug: multiple responses does not affect status code #223

Open
adminy opened this issue Mar 2, 2023 · 1 comment
Open

Bug: multiple responses does not affect status code #223

adminy opened this issue Mar 2, 2023 · 1 comment

Comments

@adminy
Copy link

adminy commented Mar 2, 2023

When a http call is being retried, only 1 call count is registered:

import requests_mock
from requests.adapters import HTTPAdapter, Retry
from requests import Session

def call_url():
  retry = Retry(total=3, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504], allowed_methods=['GET'])
  adapter = HTTPAdapter(max_retries=retry)
  http = Session()
  http.mount("http://", adapter)
  http.get(f"http://localhost")

responses = [
 {'status_code': 429},
 {'status_code': 504},
 {'status_code': 200},
]

with requests_mock.Mocker() as m:
   m.get('http://localhost', responses) 
   call_url()
   assert m.call_count == 3

There should be 3 calls, but only 1 call happens.

Sounds like the http status code isn't propagated properly

@jamielennox
Copy link
Owner

This one i can't fix unfortunately. Requests_mock mocks out the Adapter as well so it's responding with the result before ever entering the retry.

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