【问题标题】:How to get assertionError in pytest hook如何在 pytest 钩子中获取 assertionError
【发布时间】:2022-11-01 13:12:05
【问题描述】:

我想从钩子pytest中的assert py中得到断言错误

@pytest.fixture(scope='function', autouse=True) def 钩子(请求): # print("测试前") get_error = request.session.testsfailed

yield

# print("after test")
test_result = request.session.testsfailed - get_error
marker = request.node.get_closest_marker("PintuTestRail")

if marker is None:
    print("there is test case id")
else:
    if test_result == 0:
        testrail_success(marker.args[0])
    else:
        testrail_failed(marker.args[0])

【问题讨论】:

    标签: python pytest assert


    【解决方案1】:

    使用assert test_result = 0 执行此操作,如果 test_result 不等于 0 会出现此错误。

    【讨论】:

    • 谢谢,如果测试是错误的,你知道如何得到消息错误吗?
    • 使用exception assertionError as e: print(e) 可以打印错误信息,这是你想要的吗?
    猜你喜欢
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多