修复Jenkins构建时allure报告合并问题,运行测试前清空allure-results目录

This commit is contained in:
qiaoxinjiu
2026-05-09 16:19:31 +08:00
parent 6a5bd58576
commit e5de735669

View File

@@ -30,6 +30,19 @@ def ensure_dirs():
os.makedirs(ALLURE_REPORT_DIR, exist_ok=True) os.makedirs(ALLURE_REPORT_DIR, exist_ok=True)
def clean_allure_results():
"""清空allure-results目录避免与上次构建的报告合并"""
if os.path.exists(ALLURE_RESULTS_DIR):
for item in os.listdir(ALLURE_RESULTS_DIR):
item_path = os.path.join(ALLURE_RESULTS_DIR, item)
if os.path.isfile(item_path):
os.remove(item_path)
elif os.path.isdir(item_path):
import shutil
shutil.rmtree(item_path)
print(f"已清空 allure-results 目录: {ALLURE_RESULTS_DIR}")
def run_pytest(args_list): def run_pytest(args_list):
"""执行pytest命令""" """执行pytest命令"""
# 设置PYTHONPATH环境变量 # 设置PYTHONPATH环境变量
@@ -273,6 +286,9 @@ def main():
# 确保目录存在 # 确保目录存在
ensure_dirs() ensure_dirs()
# 清空上次构建的allure-results避免报告合并
clean_allure_results()
# 执行测试 # 执行测试
exit_code = 0 exit_code = 0