运行接口自动化测试,偶发性接口超时(time out)怎么办?

如图:

 使用jenkins执行自动化脚本,但是频繁遇到下面这样的问题,而中断测试:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='appts.xxxx.com', port=443): Max retries exceeded with url: /appapi/order/16/v1/list (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1619094748>: Failed to establish a new connection: [Errno -2] Name or service not known',))

 但是相同的case(测试数据也相同)在生产环境跑,却没有问题

经过排查(和开发沟通),是appts环境(预生产环境),做了安全防护,需要绑定host

于是,在修改host文件之后,再次通过jenkins构建 接口自动化脚本,就不会遇到 响应超时的问题了.

绑定host的操作方法如下:

打开hosts文件,

nano /etc/hosts

把appts环境的ip 及 域名添加到hosts文件中即可.格式:

xxx.xxx.xxx.xxx appts.xxx.com

ip地址,找开发要

修改之后运行就正常了

原文地址:https://www.cnblogs.com/kaerxifa/p/12765614.html