调整发送钉钉/企业微信/邮件里面关于测试人员信息,参数替换没有成功的问题

This commit is contained in:
floraachy
2023-11-17 14:21:16 +08:00
parent 4c175e101c
commit 2d79a82dc3
5 changed files with 91 additions and 68 deletions
@@ -3,10 +3,9 @@
# @Author : chenyinhua
# @File : send_result_handle.py
# @Software: PyCharm
# @Desc: 根据配置文件,发送指定类型的测试结果
# @Desc: 根据配置文件,发送指定通知
# 标准库导入
# 第三方库导入
# 第三方模块
from loguru import logger
# 本地应用/模块导入
from config.models import NotificationType
@@ -72,18 +71,21 @@ def send_wechat(webhook_url, content, attachment=None):
logger.error(f"发送企业微信通知异常, 错误信息:{e}")
def send_result(report_path, attachment_path=None):
def send_result(report_info: dict, report_path: str, attachment_path: str = None):
"""
根据用户配置,采取指定方式,发送测试结果
:param report_info: 报告相关信息,包括tester, department, env
:param report_path: 报告路径
:param attachment_path: 发送的附件, pytest-html就是报告本身作为附件发送, allure是压缩包发送
"""
# 默认不发送任何通知
if SEND_RESULT_TYPE == NotificationType.DEFAULT.value:
logger.debug(f"SEND_RESULT_TYPE={SEND_RESULT_TYPE} 配置了不发送任何邮件")
logger.info(f"SEND_RESULT_TYPE={SEND_RESULT_TYPE} 配置了不发送任何邮件")
return
results = get_test_results_from_from_allure_report(report_path)
for k, v in report_info.items():
results[k] = v
# 建立发送消息的内容、函数以及参数的映射关系
notification_mappings = {
@@ -121,7 +123,7 @@ def send_result(report_path, attachment_path=None):
if SEND_RESULT_TYPE in notification_mappings:
notification = notification_mappings[SEND_RESULT_TYPE]
# 获取消息内容并替换
notification['sender_args']['content'] = data_handle(notification['sender_args']['content'],
notification['sender_args']['content'] = data_handle(obj=notification['sender_args']['content'],
source=results)
# 获取消息发送函数
sender = notification['sender']
@@ -134,7 +136,7 @@ def send_result(report_path, attachment_path=None):
# 遍历所有消息发送方式
for notification in notification_mappings.values():
# 获取消息内容并替换
notification['sender_args']['content'] = data_handle(notification['sender_args']['content'],
notification['sender_args']['content'] = data_handle(obj=notification['sender_args']['content'],
source=results)
# 获取消息发送函数
sender = notification['sender']