接口自动化——超时处理

为什么接口测试需要请求超时处理

超时设置示例

class TestTimeout:
    def setup_class(self):
        self.proxies = {
            "http": "http://127.0.0.1:8888",
            "https": "http://127.0.0.1:8888"
        }

    def test_case01(self):
        url = "https://httpbin.ceshiren.com/cookies"
        resp = requests.get(url, verify=False,timeout=2)
        assert resp.status_code == 200

    def test_case02(self):
        url = "https://httpbin.ceshiren.com/cookies"
        resp = requests.get(url, verify=False,proxies=self.proxies,timeout=2)
        assert resp.status_code == 200

    def test_case03(self):
        url = "https://httpbin.ceshiren.com/cookies"
        resp = requests.get(url, verify=False,timeout=2)
        assert resp.status_code == 200