测试报告阉割掉pytest-html,只支持allure生成测试报告

This commit is contained in:
floraachy
2023-08-02 11:25:54 +08:00
parent bc25d5156b
commit 0fbd9eb5c8
13 changed files with 102 additions and 465 deletions
+8 -9
View File
@@ -1,15 +1,18 @@
# -*- coding: utf-8 -*-
# @Time : ${now}
# 标准库导入
# 第三方库导入
import pytest
from loguru import logger
import allure
from loguru import logger
# 本地应用/模块导入
from config.settings import db_info
from config.global_vars import GLOBAL_VARS
from case_utils.assert_handle import assert_response, assert_sql
from case_utils.request_data_handle import RequestPreDataHandle, RequestHandle, after_request_extract
from case_utils.allure_handle import allure_title
from config.settings import db_info
from config.global_vars import GLOBAL_VARS
from pytest_html import extras # 往pytest-html报告中填写额外的内容
# 用例数据
cases = ${case_data}
@@ -22,19 +25,15 @@ class ${class_title}Auto:
@allure.story("${allure_story}")
@pytest.mark.auto
@pytest.mark.parametrize("case", cases, ids=["{}".format(case["title"]) for case in cases])
def ${func_title}_auto(self, case, extra):
def ${func_title}_auto(self, case):
logger.info("\n-----------------------------START-开始执行用例-----------------------------\n")
logger.debug(f"当前执行的用例数据:{case}")
# 添加用例标题作为allure中显示的用例标题
allure_title(case.get("title", ""))
# 处理请求前的用例数据
case_data = RequestPreDataHandle(case).request_data_handle()
# 将用例数据显示在pytest-html报告中
extra.append(extras.text(str(case_data), name="用例数据"))
# 发送请求
response = RequestHandle(case_data).http_request()
# 将响应数据显示在pytest-html报告中
extra.append(extras.text(str(response.text), name="响应数据"))
# 进行响应断言
assert_response(response, case_data["assert_response"])
# 进行数据库断言
+4 -4
View File
@@ -13,10 +13,10 @@ CUSTOM_MARKERS = []
ENV_VARS = {
"common": {
"report_title": "自动化测试报告",
"project_name": "GitLink 确实开源",
"tester": "陈银花",
"department": "开源中心"
"报告标题": "自动化测试报告",
"项目名称": "GitLink 确实开源",
"测试人": "陈银花",
"所属部门": "开源中心"
},
"test": {
# 示例测试环境及示例测试账号
@@ -1,54 +0,0 @@
/* change pytest-html test report style */
@charset "UTF-8";
body {
font-size: 16px;
}
h1 {
text-align: center;
color: #2084D9;
font-size: 30px;
}
h2 {
font-size: 24px;
color: #2084D9;
}
a {
color: #466AFF;
}
span {
font-size: 20px;
}
#environment td {
padding: 10px;
}
#results-table {
font-size: 16px;
table-layout:fixed;
}
#results-table td{
word-break:break-all;
word-wrap:break-word;
}
#results-table th{
font-size: 20px;
background-color: #2084D9;
color: #FFFFFF;
}
td {
color: #000000;
}