diff --git a/case_utils/allure_handle.py b/case_utils/allure_handle.py index c2a9cdc..da693f4 100644 --- a/case_utils/allure_handle.py +++ b/case_utils/allure_handle.py @@ -111,7 +111,7 @@ class AllureReportBeautiful: with open(title_filepath, 'w', encoding="utf-8") as f: json.dump(new_params, f, ensure_ascii=False, indent=4) - def set_report_env(self, env_info): + def set_report_env_on_results(self, env_info): """ 在allure-results报告的根目录下生成一个写入了环境信息的文件:environment.properties(注意:不能放置中文,否则会出现乱码) @param env_info: 需要写入的环境信息 @@ -122,6 +122,20 @@ class AllureReportBeautiful: for k, v in env_info.items(): f.write('{}={}\n'.format(k, v)) + def set_report_env_on_html(self, env_info: dict): + """ + 在allure-html报告中往widgets/environment.json中写入环境信息, + 格式参考如下:[{"values":["Auto Test Report"],"name":"report_title"},{"values":["autotestreport_"]] + """ + envs = [] + for k, v in env_info.items(): + envs.append({ + "name": k, + "values": [v] + }) + with open(os.path.join(self.allure_html_path, "widgets", "environment.json"), 'w', encoding="utf-8") as f: + json.dump(envs, f, ensure_ascii=False, indent=4) + def allure_logo_change(allure_path, logo_path): """ diff --git a/config/settings.py b/config/settings.py index eea63cc..23d831a 100644 --- a/config/settings.py +++ b/config/settings.py @@ -14,14 +14,13 @@ CASE_FILE_TYPE = 1 SEND_RESULT_TYPE = 4 # 测试报告的定制化信息展示 -# 这个需要写入到allure测试结果集的environment.properties(不支持中文) ENV_INFO = { - "report_title": "Auto Test Report", - "report_name": "autotestreport_", - "project_name": "GitLink", - "tester": "floraachy", - "department": "OpenSource" -} + "report_title": "自动化测试报告", + "report_name": "autotestreport_", + "project_name": "GitLink 确实开源", + "tester": "陈银花", + "department": "开源中心" + } # 指定日志收集级别 LOG_LEVEL = "INFO" diff --git a/run.py b/run.py index e4a58bb..8f8002d 100644 --- a/run.py +++ b/run.py @@ -94,9 +94,6 @@ def run(env, m, report): """ pytest.main(args=arg_list) # ------------------------ 使用allure生成测试报告 ------------------------ - # 往allure测试结果集目录写入环境配置相关信息 - ENV_INFO["project_env"] = env - AllureReportBeautiful(allure_results_path=ALLURE_RESULTS_DIR).set_report_env(env_info=ENV_INFO) logger.debug("-------开始生成allure测试报告-------") plat = PlatformHandle() # 从LIB_DIR目录中寻找以allure开头的目录作为allure模块的目录,并进入bin目录下 @@ -110,6 +107,9 @@ def run(env, m, report): new_title=ENV_INFO["project_name"]) AllureReportBeautiful(allure_html_path=ALLURE_HTML_DIR).set_report_name(new_name=ENV_INFO["report_title"]) logger.debug("-------allure测试报告生成完毕,开始发送测试报告-------") + # 往allure测试报告中写入环境配置相关信息 + ENV_INFO["project_env"] = env + AllureReportBeautiful(allure_html_path=ALLURE_HTML_DIR).set_report_env_on_html(env_info=ENV_INFO) # 发送从allure-html获取的测试报告 results = get_test_results_from_from_allure_report(ALLURE_HTML_DIR) # 压缩allure-html报告为一个压缩文件zip