将环境数据与配置数据, 模型数据隔离开,同步修改了配套相关代码

This commit is contained in:
floraachy
2023-05-25 15:59:00 +08:00
parent c9595c8ca2
commit 9904ba8626
14 changed files with 159 additions and 196 deletions
+6 -4
View File
@@ -6,20 +6,22 @@ from pytest_html import extras # 往pytest-html报告中填写额外的内容
from common_utils.func_handle import add_docstring
from case_utils.allure_handle import allure_title
import allure
from config.settings import db_info
from config.global_vars import GLOBAL_VARS
# 用例数据
cases = ${case_data}
@allure.story(f'{cases["case_common"]["allure_story"]}')
@pytest.mark.${func_title}
@pytest.mark.auto
@pytest.mark.parametrize("case", cases.get("case_info"))
def ${func_title}_auto(case, extra, request):
def ${func_title}_auto(case, extra):
logger.info("-----------------------------START-开始执行用例-----------------------------")
logger.debug(f"当前执行的用例数据:{case}")
try:
# 获取命令行参数,判断当前处于哪个环境
env = request.config.getoption("--env")
# 给当前测试方法添加文档注释
add_docstring(case.get("title", ""))(${func_title}_auto)
# 添加用例标题作为allure中显示的用例标题
@@ -36,7 +38,7 @@ def ${func_title}_auto(case, extra, request):
# 进行响应断言
assert_response(response, case_data["assert_response"])
# 进行数据库断言
assert_sql(env, case_data["assert_sql"])
assert_sql(db_info[GLOBAL_VARS["env_key"]], case_data["assert_sql"])
else:
reason = f"标记了该用例为false,不执行\\n"
logger.warning(f"{reason}")
+30 -53
View File
@@ -1,60 +1,37 @@
# -*- coding: utf-8 -*-
# @Version: Python 3.9
# @Time : 2023/1/31 14:31
# @Time : 2023/5/25 14:52
# @Author : chenyinhua
# @File : global_vars.py
# @Software: PyCharm
# @Desc: 全局变量
from enum import Enum, unique # python 3.x版本才能使用
# 定义一个全局变量,作用于接口关联数据存储
# @Desc:
# 定义一个全局变量,用于存储运行过程中相关数据
GLOBAL_VARS = {}
ENV_VARS = {
"common": {
"report_title": "自动化测试报告",
"project_name": "GitLink 确实开源",
"tester": "陈银花",
"department": "开源中心"
},
"test": {
# 示例测试环境及示例测试账号
"host": "https://testforgeplus.trustie.net/",
"login": "auotest",
"password": "12345678",
"nickname": "AutoTest",
"user_id": "84954",
"project_id": "",
"project": ""
class CaseFileType(Enum):
"""
用例数据可存储文件的类型枚举
"""
YAML = 1
EXCEL = 2
ALL = 0
class NotificationType(Enum):
""" 自动化通知方式 """
DEFAULT = 0
DING_TALK = 1
WECHAT = 2
EMAIL = 3
ALL = 4
@unique # 枚举类装饰器,确保只有一个名称绑定到任何一个值。
class AllureAttachmentType(Enum):
"""
allure 报告的文件类型枚举
"""
TEXT = "txt"
CSV = "csv"
TSV = "tsv"
URI_LIST = "uri"
HTML = "html"
XML = "xml"
JSON = "json"
YAML = "yaml"
PCAP = "pcap"
PNG = "png"
JPG = "jpg"
SVG = "svg"
GIF = "gif"
BMP = "bmp"
TIFF = "tiff"
MP4 = "mp4"
OGG = "ogg"
WEBM = "webm"
PDF = "pdf"
},
"live": {
"host": "https://www.gitlink.org.cn",
"login": "******",
"password": "******",
"nickname": "******",
"user_id": "******",
"project_id": "",
"project": ""
}
}
+57
View File
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# @Version: Python 3.9
# @Time : 2023/1/31 14:31
# @Author : chenyinhua
# @File : models.py
# @Software: PyCharm
# @Desc: 全局变量
from enum import Enum, unique # python 3.x版本才能使用
class CaseFileType(Enum):
"""
用例数据可存储文件的类型枚举
"""
YAML = 1
EXCEL = 2
ALL = 0
class NotificationType(Enum):
""" 自动化通知方式 """
DEFAULT = 0
DING_TALK = 1
WECHAT = 2
EMAIL = 3
ALL = 4
@unique # 枚举类装饰器,确保只有一个名称绑定到任何一个值。
class AllureAttachmentType(Enum):
"""
allure 报告的文件类型枚举
"""
TEXT = "txt"
CSV = "csv"
TSV = "tsv"
URI_LIST = "uri"
HTML = "html"
XML = "xml"
JSON = "json"
YAML = "yaml"
PCAP = "pcap"
PNG = "png"
JPG = "jpg"
SVG = "svg"
GIF = "gif"
BMP = "bmp"
TIFF = "tiff"
MP4 = "mp4"
OGG = "ogg"
WEBM = "webm"
PDF = "pdf"
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# @Time : 2023/5/16 11:12
# @Author : chenyinhua
# @File : project_path.py
# @File : path_config.py
# @Software: PyCharm
# @Desc:
+23 -57
View File
@@ -13,43 +13,29 @@ CASE_FILE_TYPE = 1
# 0表示默认不发送任何通知, 1代表钉钉通知,2代表企业微信通知, 3代表邮件通知, 4代表所有途径都发送通知
SEND_RESULT_TYPE = 0
# 测试报告的定制化信息展示
ENV_INFO = {
"report_title": "自动化测试报告",
"report_name": "autotestreport_",
"project_name": "GitLink 确实开源",
"tester": "陈银花",
"department": "开源中心"
}
# 指定日志收集级别
LOG_LEVEL = "INFO"
# ------------------------------------ 测试数据 ----------------------------------------------------#
test = [
{
# 示例测试环境及示例测试账号
"host": "https://testforgeplus.trustie.net/",
"login": "auotest",
"password": "12345678",
"nickname": "AutoTest",
"user_id": "84954",
"project_id": "",
"project": ""
# ------------------------------------ 数据库相关配置 ----------------------------------------------------#
db_info = {
"test": {
"db_host": "xx.xx.xx.xx",
"db_port": 3306,
"db_user": "root",
"db_pwd": "**********",
"db_database": "test**********",
"ssh": True,
"ssh_host": "xx.xx.xx.xx",
"ssh_port": 3306,
"ssh_user": "root",
"ssh_pwd": "**********"
},
"live": {
}
]
live = [
{
"host": "https://www.gitlink.org.cn",
"login": "******",
"password": "******",
"nickname": "******",
"user_id": "******",
"project_id": "",
"project": ""
}
]
}
# ------------------------------------ 邮件配置信息 ----------------------------------------------------#
@@ -62,7 +48,7 @@ email = {
}
# ------------------------------------ 邮件通知内容 ----------------------------------------------------#
email_subject = f"{ENV_INFO.get('project_name', None)} 接口自动化报告"
email_subject = f"接口自动化报告"
email_content = """
各位同事, 大家好:
@@ -70,7 +56,7 @@ email_content = """
---------------------------------------------------------------------------------------------------------------
测试人:<strong> ${tester} </strong>
所属部门:<strong> ${department} </strong>
项目环境:<strong> ${project_env} </strong>
项目环境:<strong> ${run_env} </strong>
---------------------------------------------------------------------------------------------------------------
执行结果如下:
&nbsp;&nbsp;用例运行总数:<strong> ${total} 个</strong>
@@ -91,7 +77,7 @@ ding_talk = {
}
# ------------------------------------ 钉钉通知内容 ----------------------------------------------------#
ding_talk_title = f"{ENV_INFO.get('project_name', None)} 接口自动化报告"
ding_talk_title = f"接口自动化报告"
ding_talk_content = """
各位同事, 大家好:
@@ -99,7 +85,7 @@ ding_talk_content = """
---------------------------------------------------------------------------------------------------------------
#### 测试人: ${tester}
#### 所属部门: ${department}
#### 项目环境:${project_env}
#### 项目环境: ${run_env}
---------------------------------------------------------------------------------------------------------------
#### 执行结果如下:
- 用例运行总数: ${total}
@@ -125,7 +111,7 @@ wechat_content = """
--------------------------------
#### 测试人: ${tester}
#### 所属部门: ${department}
#### 项目环境:${project_env}
#### 项目环境: ${run_env}
--------------------------------
#### 执行结果如下:
- 用例运行总数: ${total}
@@ -139,23 +125,3 @@ wechat_content = """
**********************************
附件为具体的测试报告,详细情况可下载附件查看, 非相关负责人员可忽略此消息。谢谢。
"""
# ------------------------------------ 数据库相关配置 ----------------------------------------------------#
db_info = {
"test": {
"db_host": "xx.xx.xx.xx",
"db_port": 3306,
"db_user": "root",
"db_pwd": "**********",
"db_database": "test**********",
"ssh": True,
"ssh_host": "xx.xx.xx.xx",
"ssh_port": 3306,
"ssh_user": "root",
"ssh_pwd": "**********"
},
"live": {
}
}