question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I made an HTTP adapter:

session = requests.Session()
session.verify = False

# Try max of 3 times before erroring out
retry_adapter = requests.adapters.HTTPAdapter(max_retries=3)
session.mount('https://', retry_adapter)

I wanted to make sure it will automatically retry, but it seems it’s not getting triggered right:

exception = ConnectionError('Bad connection')
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsp:
   rsp.add(responses.POST, url, body=exception)
   rsp.add(responses.POST, url, body=exception)
   rsp.add(responses.POST, url, body='{}')
   session.post(url=url, json={})

It just keeps raising the exception.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:28
  • Comments:26 (6 by maintainers)

github_iconTop GitHub Comments

19reactions
belthaZornvcommented, Jul 23, 2018

Same here, trying to test a session with Retry.

8reactions
pbelskiycommented, Nov 5, 2020

+1

Retry don’t work with responses lib, so I think at least it would be nice to write about such limitation in readme or docs.

#!/usr/local/bin/python3

import requests
import responses

from requests.packages.urllib3.util.retry import Retry


@responses.activate
def test():
    responses.add(responses.GET, 'https://google.com', body='Error', status=500)
    responses.add(responses.GET, 'https://google.com', body='OK', status=200)

    session = requests.Session()

    adapter = requests.adapters.HTTPAdapter(max_retries=Retry(
        total=2,
        backoff_factor=0.1,
        status_forcelist=[500],
        method_whitelist=['GET', 'POST', 'PATCH']
    ))
    session.mount('http://', adapter)
    session.mount('https://', adapter)

    r = session.get('https://google.com')
    print(r)


test()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Retries | Cypress Documentation
With test retries, Cypress is able to retry failed tests to help reduce test flakiness and continuous integration (CI) build failures.
Read more >
Retry Flaky Tests - WebdriverIO
You can rerun certain tests with the WebdriverIO testrunner that turn out to be unstable due to things like a flaky network or...
Read more >
Retrying Failing Tests - JUnit Pioneer
The JUnit 5 (Jupiter) extension @RetryingTest retries a failing test a certain number of times; only marking the test failed if no execution...
Read more >
"Max retries exceeded" error when running real device test ...
The Python bindings use urllib3 to create HTTP connections and by default urllib3 has a 3 retry limit. Sauce Labs sends a 303...
Read more >
Retry - NUnit Docs
RetryAttribute is used on a test method to specify that it should be rerun if it fails, up to a maximum number of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found