MCPcopy
hub / github.com/urllib3/urllib3 / test_retries

Function test_retries

test/contrib/emscripten/test_emscripten.py:905–937  ·  view source on GitHub ↗
(
    selenium_coverage: typing.Any, testserver_http: PyodideServerInfo
)

Source from the content-addressed store, hash-verified

903
904
905def test_retries(
906 selenium_coverage: typing.Any, testserver_http: PyodideServerInfo
907) -> None:
908 @run_in_pyodide # type: ignore[untyped-decorator]
909 def pyodide_test(selenium_coverage, host: str, port: int) -> None: # type: ignore[no-untyped-def]
910 import pytest
911
912 import urllib3
913
914 pool = urllib3.HTTPConnectionPool(
915 host,
916 port,
917 maxsize=1,
918 block=True,
919 retries=urllib3.util.Retry(connect=5, read=5, redirect=5),
920 )
921
922 # monkeypatch connection class to count calls
923 old_request = urllib3.connection.HTTPConnection.request
924 count = 0
925
926 def count_calls(self, *args, **argv): # type: ignore[no-untyped-def]
927 nonlocal count
928 count += 1
929 return old_request(self, *args, **argv)
930
931 urllib3.connection.HTTPConnection.request = count_calls # type: ignore[method-assign]
932 with pytest.raises(urllib3.exceptions.MaxRetryError):
933 pool.urlopen("GET", "/")
934 # this should fail, but should have tried 6 times total
935 assert count == 6
936
937 pyodide_test(selenium_coverage, testserver_http.http_host, find_unused_port())
938
939
940def test_redirects(

Callers

nothing calls this directly

Calls 2

pyodide_testFunction · 0.85
find_unused_portFunction · 0.85

Tested by

no test coverage detected