Skip to content

Commit

Permalink
adjust error message when Retry is exhausted (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim committed Sep 6, 2022
1 parent 7318ddd commit 60931f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -11,6 +11,7 @@
* Add lists support as JSON objects in `json_params_matcher`. See #559
* Added project links to pypi listing.
* Fix `MaxRetryError` exception. Replace exception by `RetryError` according to `requests` implementation. See #572.
* Adjust error message when `Retry` is exhausted. See #580.

0.21.0
------
Expand Down
2 changes: 1 addition & 1 deletion responses/__init__.py
Expand Up @@ -1048,7 +1048,7 @@ def _on_request(
retries = retries.increment(
method=response.request.method, # type: ignore[misc]
url=response.url, # type: ignore[misc]
response=response, # type: ignore[misc]
response=response.raw, # type: ignore[misc]
)
return self._on_request(adapter, request, retries=retries, **kwargs)
except MaxRetryError as e:
Expand Down
17 changes: 17 additions & 0 deletions responses/tests/test_responses.py
Expand Up @@ -2450,6 +2450,23 @@ def run():
run()
assert_reset()

def test_max_retries_exceed_msg(self):
@responses.activate(registry=registries.OrderedRegistry)
def run():
url = "https://example.com"
responses.get(url, body="Error", status=500)
responses.get(url, body="Error", status=500)

session = self.set_session(total=1)

with pytest.raises(RetryError) as err:
session.get(url)

assert "too many 500 error responses" in str(err.value)

run()
assert_reset()

def test_adapter_retry_untouched(self):
"""Validate that every new request uses brand-new Retry object"""

Expand Down

0 comments on commit 60931f1

Please sign in to comment.