add some tests for passing in Timeout objects
@@ -2025,6 +2025,20 @@ class TestTimeout:
r = requests.get(httpbin('get'), timeout=None)
assert r.status_code == 200
+ def test_none_timeout_obj(self, httpbin):
+ """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 forever. 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.
+ """
+ from requests.packages.urllib3.util import Timeout
+ r = requests.get(httpbin('get'),
+ timeout=Timeout(connect=None, read=None))
+ assert r.status_code == 200
+
def test_read_timeout(self, httpbin):
try:
requests.get(httpbin('delay/10'), timeout=(None, 0.1))
@@ -2032,6 +2046,15 @@ class TestTimeout:
except ReadTimeout:
pass
+ def test_read_timeout_obj(self, httpbin):
+ from requests.packages.urllib3.util import Timeout
+ try:
+ requests.get(httpbin('delay/10'),
+ timeout=Timeout(connect=None, read=0.1))
+ pytest.fail('The recv() request should time out.')
+ except ReadTimeout:
+ pass
+
def test_connect_timeout(self):
try:
requests.get(TARPIT, timeout=(0.1, None))
@@ -2040,6 +2063,16 @@ class TestTimeout:
assert isinstance(e, ConnectionError)
assert isinstance(e, Timeout)
+ def test_connect_timeout_obj(self):
+ from requests.packages.urllib3.util import Timeout
+ try:
+ requests.get(TARPIT,
+ timeout=Timeout(connect=0.1, read=None))
+ pytest.fail('The connect() request should time out.')
+ except ConnectTimeout as e:
+ assert isinstance(e, ConnectionError)
+ assert isinstance(e, Timeout)
+
def test_total_timeout_connect(self):
try:
requests.get(TARPIT, timeout=(0.1, 0.1))
@@ -2047,6 +2080,15 @@ class TestTimeout:
except ConnectTimeout:
pass
+ def test_total_timeout_connect_obj(self):
+ from requests.packages.urllib3.util import Timeout
+ try:
+ requests.get(TARPIT,
+ timeout=Timeout(connect=0.1, read=0.1))
+ pytest.fail('The connect() request should time out.')
+ except ConnectTimeout:
+ pass
+
def test_encoded_methods(self, httpbin):
"""See: https://github.com/kennethreitz/requests/issues/2316"""
r = requests.request(b'GET', httpbin('get'))
