首页 > 解决方案 > 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))

标签: pythonexceptionallurepython-behave

解决方案


推荐阅读