python - Allure 报告中的测试失败报告
问题描述
我正在使用以下 Try except 方法来处理断言错误。但是对于真正的断言错误,我在 Allure 报告中没有得到任何失败状态。因此,即使实际上测试用例由于断言错误而失败,诱惑报告显示 100% 通过。是否可以在 allure 报告中报告由于断言错误而导致的真正测试失败?
@then('Premium is generated for {status},{exp_date},{owner},{reg_date},{man_yr},{vchl_make},{vchl_code} accordingly')
def step_impl(context, status, exp_date, owner, reg_date, man_yr, vchl_make, vchl_code):
if context.conv_exp_date < context.conv_expnd_date:
if context.conv_reg_date >= '01-09-2018':
if man_yr == context.expctd_manu_year:
if not context.json_response:
print("empty response")
json_data = context.payload
sys.stdout = open("OD_Plans.log", "a")
print("Previous Policy Status=" + " " + status)
print("expiry date=" + " " + exp_date)
print("Owner=" + " " + owner)
print("Registration Date=" + " " + reg_date)
print("Manufacturing Year=" + " " + man_yr)
print("Veichle Maker=" + " " + vchl_make)
print("Maker Code=" + " " + vchl_code)
print(json.dumps(json_data, indent=2))
else:
try:
assert context.json_response is not None
assert float(context.json_response[0]['base_premium']) > float(1)
assert float(context.json_response[0]['total_premium']) < float(1)
assert float(context.json_response[0]['tax']) > float(1)
print(context.json_response[0]["tax"])
except AssertionError:
json_data = context.payload
sys.stdout = open("OD_Plans.log", "a")
print("Test failure due to assertion error")
print("Previous Policy Status=" + " " + status)
print("expiry date=" + " " + exp_date)
print("Owner=" + " " + owner)
print("Registration Date=" + " " + reg_date)
print("Manufacturing Year=" + " " + man_yr)
print("Veichle Maker=" + " " + vchl_make)
print("Maker Code=" + " " + vchl_code)
print(json.dumps(json_data, indent=2))
解决方案
推荐阅读
- c# - aps.net MVC MultiSlectList 所选项目不起作用
- ubuntu-16.04 - bigbluebutton 安装问题
- linux - 一个接一个地从一个文件夹运行severel脚本
- c++ - 从 std::priority_que 复制到 typdef 边缘
- sql - 如何在查询中使用来自另一个表的输入?
- delphi - delphi 类在运行时确定
- adaboost - Viola-Jones 人脸检测和每个弱分类器的特征
- angular - 只有在嵌套请求完成后才返回 Observable
- python - 使用 xPath 从父节点和后代节点中提取文本
- php - 如何在数组中包含多个键和值