TestTimeout Class — requests Architecture
Architecture documentation for the TestTimeout class in test_requests.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 197b2331_292a_b6cc_3228_c8b753441d51["TestTimeout"] 6d0b23d4_0fe8_9017_3d1a_9c023311c6a7["ConnectionError"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|extends| 6d0b23d4_0fe8_9017_3d1a_9c023311c6a7 7c3894c2_8bb4_1123_4ed5_540187e58dd8["Timeout"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|extends| 7c3894c2_8bb4_1123_4ed5_540187e58dd8 69ebfd6f_8f0c_4586_0c19_2c348e1a42a2["test_requests.py"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|defined in| 69ebfd6f_8f0c_4586_0c19_2c348e1a42a2 1d6399d0_d5e5_4006_326d_91bc82fa6503["test_stream_timeout()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| 1d6399d0_d5e5_4006_326d_91bc82fa6503 ebd52efe_fbf1_d9e3_1f25_11de3ff967d3["test_invalid_timeout()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| ebd52efe_fbf1_d9e3_1f25_11de3ff967d3 5f03e7bc_40ea_b100_bc0f_25e072915581["test_none_timeout()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| 5f03e7bc_40ea_b100_bc0f_25e072915581 b8403bfc_ba4c_f749_27a6_ca255caff720["test_read_timeout()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| b8403bfc_ba4c_f749_27a6_ca255caff720 f330e754_89ab_b42e_a095_9d931dd51f9c["test_connect_timeout()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| f330e754_89ab_b42e_a095_9d931dd51f9c 23889ad6_2193_34aa_38aa_f704ff3d64aa["test_total_timeout_connect()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| 23889ad6_2193_34aa_38aa_f704ff3d64aa 2755ff0d_bf73_49bf_0057_2131c358aa4a["test_encoded_methods()"] 197b2331_292a_b6cc_3228_c8b753441d51 -->|method| 2755ff0d_bf73_49bf_0057_2131c358aa4a
Relationship Graph
Source Code
tests/test_requests.py lines 2482–2548
class TestTimeout:
def test_stream_timeout(self, httpbin):
try:
requests.get(httpbin("delay/10"), timeout=2.0)
except requests.exceptions.Timeout as e:
assert "Read timed out" in e.args[0].args[0]
@pytest.mark.parametrize(
"timeout, error_text",
(
((3, 4, 5), "(connect, read)"),
("foo", "must be an int, float or None"),
),
)
def test_invalid_timeout(self, httpbin, timeout, error_text):
with pytest.raises(ValueError) as e:
requests.get(httpbin("get"), timeout=timeout)
assert error_text in str(e)
@pytest.mark.parametrize("timeout", (None, Urllib3Timeout(connect=None, read=None)))
def test_none_timeout(self, httpbin, timeout):
"""Check that you can set None as a valid timeout value.
To actually test this behavior, we'd want to check that setting the
timeout to None actually lets the request block past the system default
timeout. However, this would make the test suite unbearably slow.
Instead we verify that setting the timeout to None does not prevent the
request from succeeding.
"""
r = requests.get(httpbin("get"), timeout=timeout)
assert r.status_code == 200
@pytest.mark.parametrize(
"timeout", ((None, 0.1), Urllib3Timeout(connect=None, read=0.1))
)
def test_read_timeout(self, httpbin, timeout):
try:
requests.get(httpbin("delay/10"), timeout=timeout)
pytest.fail("The recv() request should time out.")
except ReadTimeout:
pass
@pytest.mark.parametrize(
"timeout", ((0.1, None), Urllib3Timeout(connect=0.1, read=None))
)
def test_connect_timeout(self, timeout):
try:
requests.get(TARPIT, timeout=timeout)
pytest.fail("The connect() request should time out.")
except ConnectTimeout as e:
assert isinstance(e, ConnectionError)
assert isinstance(e, Timeout)
@pytest.mark.parametrize(
"timeout", ((0.1, 0.1), Urllib3Timeout(connect=0.1, read=0.1))
)
def test_total_timeout_connect(self, timeout):
try:
requests.get(TARPIT, timeout=timeout)
pytest.fail("The connect() request should time out.")
except ConnectTimeout:
pass
def test_encoded_methods(self, httpbin):
"""See: https://github.com/psf/requests/issues/2316"""
r = requests.request(b"GET", httpbin("get"))
assert r.ok
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the TestTimeout class?
TestTimeout is a class in the requests codebase, defined in tests/test_requests.py.
Where is TestTimeout defined?
TestTimeout is defined in tests/test_requests.py at line 2482.
What does TestTimeout extend?
TestTimeout extends ConnectionError, Timeout.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free