From 60931f1cbeffebca85a42b52f3a40fe14d873b21 Mon Sep 17 00:00:00 2001 From: Maksim Beliaev Date: Tue, 6 Sep 2022 16:33:43 +0200 Subject: [PATCH] adjust error message when Retry is exhausted (#580) --- CHANGES | 1 + responses/__init__.py | 2 +- responses/tests/test_responses.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f1c66f30..e9e3ce07 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ------ diff --git a/responses/__init__.py b/responses/__init__.py index df372a01..35dc0ed5 100644 --- a/responses/__init__.py +++ b/responses/__init__.py @@ -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: diff --git a/responses/tests/test_responses.py b/responses/tests/test_responses.py index be87497e..53924df7 100644 --- a/responses/tests/test_responses.py +++ b/responses/tests/test_responses.py @@ -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"""