logger.info("执行设备管理:正确密码连接---TestCase1---") data = { "passwd": 1234 } try: #传输data-passwd数据,执行DeviceManagement-Connect方法 self.cns.Connect(**data) assert self.cns.dlg['Connected'].exists() logger.info("设备管理:正确密码连接---测试PASS---") except Exception as e: logger.info("FAIL") logger.error(str(e)) logger.info("设备管理:正确密码连接---测试FAIL---") self.assertEqual(True, False) 用例如果执行失败,则再次重复执行,重复3次仍失败,则判定为失败 这个要怎么改
时间: 2024-02-14 22:13:38 浏览: 100
根据你的要求,如果测试用例执行失败,则需要重复执行3次,如果3次重复执行仍然失败,则判定为失败。你可以使用一个循环来实现重复执行的功能,同时还需要记录重复执行的次数。下面是修改后的代码:
```
logger.info("执行设备管理:正确密码连接---TestCase1---")
data = {
"passwd": 1234
}
max_retry = 3 // 最大重试次数
retry_count = 0 // 当前重试次数
test_result = False // 测试结果,默认为失败
while retry_count < max_retry and not test_result:
try:
# 传输data-passwd数据,执行DeviceManagement-Connect方法
self.cns.Connect(**data)
assert self.cns.dlg['Connected'].exists()
logger.info("设备管理:正确密码连接---测试PASS---")
test_result = True
except Exception as e:
retry_count += 1
logger.info(f"第{retry_count}次重试")
logger.error(str(e))
logger.info("设备管理:正确密码连接---测试FAIL---")
if not test_result:
logger.info("FAIL")
self.assertEqual(True, False)
```
这样修改后,如果测试用例执行失败,则会进行最多3次的重复执行,如果3次重复执行仍然失败,则判定为失败。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)