增加重试用例统计

This commit is contained in:
wangjie 2025-04-08 20:59:46 +08:00
parent ef61a029d1
commit 219fa1c91e
4 changed files with 6 additions and 1 deletions

View File

@ -16,6 +16,7 @@ class TestMetrics:
""" 用例结果数据 """
total: int
passed: int
rerun: int
failed: int
skipped: int
xfailed: int

View File

@ -61,6 +61,7 @@ email_content = """
执行结果如下:<br>
&nbsp;&nbsp;用例运行总数:<strong> ${total}</strong><br>
&nbsp;&nbsp;通过用例数passed: <strong><font color="green" >${passed}</font></strong><br>
&nbsp;&nbsp;重试通过用例数rerun: <strong><font color="green" >${rerun}</font></strong><br>
&nbsp;&nbsp;失败用例数failed: <strong><font color="red" >${failed}</font></strong><br>
&nbsp;&nbsp;报错用例数error: <strong><font color="orange" >${error}</font></strong><br>
&nbsp;&nbsp;跳过用例数skipped: <strong><font color="grey" >${skipped}</font></strong><br>
@ -86,6 +87,7 @@ wechat_content = """******用例执行结果统计******
> 测试环境:%s
> 总用例数<font color=\"info\">${total}条</font>
> 通过用例数<font color=\"info\">${passed}条</font>
> 重试通过用例数<font color=\"info\">${rerun}条</font>
> 失败用例数<font color=\"red\">${failed}条</font>
> 报错用例数<font color=\"red\">${error}条</font>
> 跳过用例数<font color=\"warning\">${skipped}条</font>

View File

@ -82,6 +82,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
print("******用例执行结果统计******")
print(f"总用例数:{pytest_result.total}")
print(f"通过:{pytest_result.passed}")
print(f"重试后通过:{pytest_result.rerun}")
print(f"失败:{pytest_result.failed}")
print(f"跳过:{pytest_result.skipped}")
print(f"预期失败:{pytest_result.xfailed}")

View File

@ -29,6 +29,7 @@ class ReportDataHandle:
case_count["total"] = pytest_result['summary'].get("total", 0) # 用例总数
case_count["passed"] = pytest_result["summary"].get("passed", 0) # 通过用例数
case_count["failed"] = pytest_result["summary"].get("failed", 0) # 失败用例数
case_count["rerun"] = pytest_result["summary"].get("rerun", 0) # 重试通过用例数
case_count["skipped"] = pytest_result["summary"].get("skipped", 0) # 跳过用例数
case_count["xfailed"] = pytest_result["summary"].get("xfailed", 0) # 预期失败用例数
case_count["xpassed"] = pytest_result["summary"].get("xpassed", 0) # 预期成功用例数
@ -37,7 +38,7 @@ class ReportDataHandle:
if case_count["total"] > 0:
# 计算成功率
case_count["pass_rate"] = round(
(case_count["passed"] + case_count["xpassed"]) / case_count["total"] * 100, 2)
(case_count["passed"] + case_count["rerun"] + case_count["xpassed"]) / case_count["total"] * 100, 2)
else:
# 如果未运行用例,则成功率为 0.0
case_count["pass_rate"] = 0.0