Comment

Swee Tat Lim

Hi,

I tried your code with the following:

```
def get_session():
    result = requests.Session()
    retries = Retry(
        total=3, connect=3, read=3,
        redirect=3, status=3, backoff_factor=1,
        status_forcelist=[429, 500, 502, 503, 504],
        method_whitelist=[
            "HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"],
    )
    adapter = HTTPAdapter(max_retries=retries)
    result.mount("http://", adapter)
    result.mount("https://", adapter)
    return result
```

In my unit test, I did the following:
```
    @responses.activate
    def test_get_session_500_retry(self):
        responses.add(responses.POST,
                      self.url,
                      status=500,
                      json={'something': 'nothing'}
                      )

        session = get_session()
        session.hooks["response"] = [logging_hook]
        print(f"url({self.url})")
        wait_time = datetime.now() + timedelta(seconds=10)
        r = session.post(self.url, timeout=10)
        waited_time = wait_time - datetime.now()
        self.assertGreaterEqual(waited_time, timedelta(seconds=0))
        self.assertEqual(r.status_code, 500)
        assert responses.assert_call_count(
            self.url, 1) is True
```

The strange part to me is that the assert_call_count is 1 instead of 3 which I set in the config

Replies

Peter Bengtsson

I think all bets are off when you use one of those request/response mocking libs.

Swee Tat Lim

How do you test reliably that the retries in the call works as expected?

Anonymous

use something like mockoon (https://mockoon.com) and set up HTTP routes for 200 OK and a couple statuses in your status_forcelist. turn on random responses and you'll see it working in the logs.