fix(exchange,case_validator),refactor(),feat(model): 解决 Pydantic 模型初始化与变量占位符的类型冲突,优化变量替换逻辑,重构 CaseInfo 模型并引入延迟校验机制

- 引入 SmartInt 和 SmartDict 类型,支持 YAML 占位符与业务类型的自动转换。
- 优化 CaseInfo 互斥校验逻辑,确保 request 与 api_action 二选一。
- 统一使用 Pydantic V2 的 model_config 规范。
- 将变量替换时机提前至模型实例化之前,支持占位符在校验前完成真实值注入,
保证了 int/bool 等字段的类型转换正确性。
- 优化断言渲染时机,支持响应提取值关联。
This commit is contained in:
2026-03-11 10:29:16 +08:00
parent 69a96a0060
commit 293b5160fe
39 changed files with 1359 additions and 1031 deletions

33
main.py
View File

@@ -1,19 +1,22 @@
import os
import shutil
import datetime
import pytest
from commons.cases import TestAPI
TestAPI.run() # 加载yaml文件
if __name__ == '__main__':
now = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
# 1启动框架生成临时文件
# -x表示有一个用例失败后面将不执行;-v表示展示用例名称;-c,配置文件所在目录指定pytest.ini路径;--alluredir=temp。指定数据生成目录
pytest.main([__file__, "-x", "-v","--alluredir=temp"])
# 2生成HTML报告
os.system('allure generate temp -o report --clean') # java程序只能借助操作系统执行
# 3备份日志
# shutil.copy2("logs/pytest.log", f"logs/pytest_{now}.log")
# 定义报告和临时文件目录
reports_dir = "reports"
temp_dir = os.path.join(reports_dir, "temp")
html_dir = os.path.join(reports_dir, "html")
# 1. 执行 Pytest 测试
# -v: 输出详细信息
# --alluredir: 指定 Allure 临时数据目录
# -c: 指定 pytest.ini 配置文件路径
pytest.main([
"-v",
"tests/", # 明确指定测试目录
f"--alluredir={temp_dir}",
"-c=config/pytest.ini"
])
# 2. 生成 Allure HTML 报告
os.system(f'allure generate {temp_dir} -o {html_dir} --clean')