问题
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