diff --git a/zhyy/test_case/run_tests.py b/zhyy/test_case/run_tests.py index 4be604a..d0494db 100644 --- a/zhyy/test_case/run_tests.py +++ b/zhyy/test_case/run_tests.py @@ -30,6 +30,19 @@ def ensure_dirs(): 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): """执行pytest命令""" # 设置PYTHONPATH环境变量 @@ -273,6 +286,9 @@ def main(): # 确保目录存在 ensure_dirs() + # 清空上次构建的allure-results,避免报告合并 + clean_allure_results() + # 执行测试 exit_code = 0