首页 > 其他 > 详细

一键生成与打开allure报告

时间:2021-03-13 12:04:11      阅读:146      评论:0      收藏:0      [点我收藏+]
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()

 

一键生成与打开allure报告

原文:https://www.cnblogs.com/teark/p/14527693.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!