How to handle rerun in pytest with pytest_runtest_makereport fixture

六眼飞鱼酱① 提交于 2020-03-25 17:44:17

问题


I am using pytest-testrail in order to publish some python test cases to testrail. I have a couple test cases that are flaky and using --rerun in order to rerun the test cases that fail. After the rerun, some test cases will pass (meaning the case failed once and passed on the rerun), but pytest will publish the test as failed and pass both.

//conftest.py file
@pytest.hookimpl(trylast=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    report = (yield).get_result()
    if report.when == "call":
        common_utils.process_test_result(item, report)


//common_utils.py file
def process_test_result(item, result):
    # test_case_name instance_num result_type : message
    test_case_name = item.originalname if item.originalname is not None else item.name
    instance_count = 1
    status = None
    message = None
    if result.passed:
        status = 'PASS'
        message = 'Test Passed'
    elif result.failed:
            status = 'FAIL'
            message = 'Test Failed'
    elif result.skipped:
        status = 'CONF'
        message = 'Test Skipped'
    if status is not None:
        logger.info("{0} {1} {2} : {3}".format(test_case_name, instance_count, status, message))

How can i remove fail count if test case is passed in second run?

来源:https://stackoverflow.com/questions/59732689/how-to-handle-rerun-in-pytest-with-pytest-runtest-makereport-fixture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!