Pythonコード
import requests
import pytest
from requests.adapters import TimeoutSauce
for default_timeout in [0.001, 10]:
def __init__(self, *args, **kwargs):
if kwargs['connect'] is None:
kwargs['connect'] = default_timeout
if kwargs['read'] is None:
kwargs['read'] = default_timeout
return TimeoutSauce.__init__(self, *args, **kwargs)
DefaultTimeout = type('DefaultTimeout', (TimeoutSauce,),{"__init__": __init__})
requests.adapters.TimeoutSauce = DefaultTimeout
if default_timeout < 1:
with pytest.raises(requests.exceptions.ConnectionError):
requests.get('https://www.google.com')
else:
result = requests.get('https://www.google.com')
assert result.status_code, 200
参考リンク
For example I have a base class as follows: class BaseClass(object): def __init__(self, classtype): self._type = classtypeFrom ...
コメント