问题:
1.为什么自动化/监控报错,黑盒不复现?
2.如何让自动化脚本更精准地体现bug所在位置?
3.通过try捕获异常的场合,debug定位问题很难,是否有解决方案?
答:
1. 自动化执行过程中,会因为场地服务不稳定/网络不稳定,导致case误报警,需要在case中增加retry来提升代码的稳定性,例如:
num = 3 # 失败重试3次
while num:
num -= 1
res = self.session.post(url=url, json=data, headers=self.headers, timeout=req_timeout)
if not res:
Log.log('接口请求失败')
error_info = '【post】 {} 错误信息:{}'.format(url, '无结果')
elif res and res.status_code != 200:
Log.log('错误码:{}'.format(res.status_code))
Log.log('接口请求失败,失败信息:{}'.format(str(res.text)))
error_info = '【post】 {} 错误码:{}'