pytest 获取用例执行状态
conftest.py
case_status = dict()
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
out = yield
report = out.get_result()
# print(report.__dict__)
if report.when == "call":
case_name = list(report.keywords.keys())[0]
if '[' in case_name:
case_name = case_name.split('[')[0]
case_status[case_name] = report.outcome
with open("test_statuses.json", "w") as f:
json.dump(case_status, f, indent=4)