use @pytest.mark.parametrize
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alexander 'Leo' Bergolth · committed by Alexander 'Leo' Bergolth · parent 93cb1ca · Browse files · 1 file·+29 added−50 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+29 added−50 removed
- tests:+29 added−50 removed
Provenance
- Commit
28768b9- Tree
f33df00- Author
Alexander 'Leo' Bergolth <leo@strike.wu.ac.at>- Committer
Alexander 'Leo' Bergolth <leo@strike.wu.ac.at>- Parent
93cb1ca
1 file changed+29 added−50 removed
modified:tests/test_requests.py+29 added-50 removed
31 unmodified lines32 from requests.hooks import default_hooks33 34 from .compat import StringIO, u35 from .utils import override_environ36+from requests.packages.urllib3.util import Timeout37 38 # Requests to this URL should always fail with a connection timeout (nothing39 # listening on that port)40 TARPIT = 'http://10.255.255.1'1972 unmodified lines2013 with pytest.raises(ValueError) as e:2014 requests.get(httpbin('get'), timeout=timeout)2015 assert error_text in str(e)2016 2017+ @pytest.mark.parametrize(2018+ 'timeout', (2019+ None,2020+ Timeout(connect=None, read=None)2021+ ))2016- def test_none_timeout(self, httpbin):2022+ def test_none_timeout(self, httpbin, timeout):2023 """Check that you can set None as a valid timeout value.2024 2025 To actually test this behavior, we'd want to check that setting the2026 timeout to None actually lets the request block past the system default2027 timeout. However, this would make the test suite unbearably slow.2028 Instead we verify that setting the timeout to None does not prevent the2029 request from succeeding.2030 """2025- r = requests.get(httpbin('get'), timeout=None)2031+ r = requests.get(httpbin('get'), timeout=timeout)2032 assert r.status_code == 2002033 2028- def test_none_timeout_obj(self, httpbin):2029- """Check that you can set None as a valid timeout value.2030-2031- To actually test this behavior, we'd want to check that setting the2032- timeout to None actually lets the request block forever. However, this2033- would make the test suite unbearably slow.2034- Instead we verify that setting the timeout to None does not prevent the2035- request from succeeding.2036- """2037- from requests.packages.urllib3.util import Timeout2038- r = requests.get(httpbin('get'),2039- timeout=Timeout(connect=None, read=None))2040- assert r.status_code == 2002041-2042- def test_read_timeout(self, httpbin):2034+ @pytest.mark.parametrize(2035+ 'timeout', (2036+ (None, 0.1),2037+ Timeout(connect=None, read=0.1)2038+ ))2039+ def test_read_timeout(self, httpbin, timeout):2040 try:2044- requests.get(httpbin('delay/10'), timeout=(None, 0.1))2041+ requests.get(httpbin('delay/10'), timeout=timeout)2042 pytest.fail('The recv() request should time out.')2043 except ReadTimeout:2044 pass2045 2049- def test_read_timeout_obj(self, httpbin):2050- from requests.packages.urllib3.util import Timeout2046+ @pytest.mark.parametrize(2047+ 'timeout', (2048+ (0.1, None),2049+ Timeout(connect=0.1, read=None)2050+ ))2051+ def test_connect_timeout(self, timeout):2052 try:2052- requests.get(httpbin('delay/10'),2053- timeout=Timeout(connect=None, read=0.1))2054- pytest.fail('The recv() request should time out.')2055- except ReadTimeout:2056- pass2057-2058- def test_connect_timeout(self):2059- try:2060- requests.get(TARPIT, timeout=(0.1, None))2053+ requests.get(TARPIT, timeout=timeout)2054 pytest.fail('The connect() request should time out.')2055 except ConnectTimeout as e:2056 assert isinstance(e, ConnectionError)2057 assert isinstance(e, Timeout)2058 2066- def test_connect_timeout_obj(self):2067- from requests.packages.urllib3.util import Timeout2059+ @pytest.mark.parametrize(2060+ 'timeout', (2061+ (0.1, 0.1),2062+ Timeout(connect=0.1, read=0.1)2063+ ))2064+ def test_total_timeout_connect(self, timeout):2065 try:2069- requests.get(TARPIT,2070- timeout=Timeout(connect=0.1, read=None))2066+ requests.get(TARPIT, timeout=timeout)2067 pytest.fail('The connect() request should time out.')2072- except ConnectTimeout as e:2073- assert isinstance(e, ConnectionError)2074- assert isinstance(e, Timeout)2075-2076- def test_total_timeout_connect(self):2077- try:2078- requests.get(TARPIT, timeout=(0.1, 0.1))2079- pytest.fail('The connect() request should time out.')2068 except ConnectTimeout:2069 pass2070 2083- def test_total_timeout_connect_obj(self):2084- from requests.packages.urllib3.util import Timeout2085- try:2086- requests.get(TARPIT,2087- timeout=Timeout(connect=0.1, read=0.1))2088- pytest.fail('The connect() request should time out.')2089- except ConnectTimeout:2090- pass2091-2071 def test_encoded_methods(self, httpbin):2072 """See: https://github.com/kennethreitz/requests/issues/2316"""2073 r = requests.request(b'GET', httpbin('get'))2074 assert r.ok301 unmodified lines