import os import shutil from config import config from pack.log import logger # config里有这个BAT_FILE = os.path.join(BASE_PATH, "bat", "generate_report.bat") RUN_SERVER_FILE = os.path.join(BASE_PATH, "bat", "run_allure_server.bat") class TestManager: def __init__(self): self.log = logger() # 旧的报告如果存在就删掉 def del_old_result(self): self.log.info("删除旧的结果集……") if os.path.exists(config.REPORT_RESULT_PATH): # shutil提供对文件的高阶操作,其他操作见https://docs.python.org/zh-cn/3/library/shutil.html shutil.rmtree(config.REPORT_RESULT_PATH) # 生成新的报告 def generate_report(self): self.log.info("生成报告……") # 终端生成报告的格式:allure generate ./reports/xml -o ./reports/html --clean os.system(f"allure generate {config.REPORT_RESULT_PATH} -o {config.REPORT_END_PATH} --clean") # 复制history文件夹,在本地生成趋势图 files = os.listdir(config.REPORT_HISTORY_PATH) allure_result = config.REPORT_RESULT_PATH # 没有就创建 if not os.path.exists(allure_result): os.mkdir(allure_result) result_history_dir = os.path.join(config.REPORT_RESULT_PATH, "history") # 没有就创建 if not os.path.exists(result_history_dir): os.mkdir(result_history_dir) for file in files: shutil.copy(os.path.join(config.REPORT_HISTORY_PATH, file), result_history_dir) # 在终端执行打开报告操作 def run_allure_server(self): self.log.info("启动allure服务!") os.system(f"allure open {config.REPORT_RESULT_PATH}") if __name__ == ‘__main__‘: report = TestManager() report.del_old_result() # report.generate_report() # report.run_allure_server()
原文:https://www.cnblogs.com/teark/p/14527693.html