feat: MES 接口自动化测试框架(unittest + HTMLTestRunner + 数据驱动)

This commit is contained in:
WbiubiuW
2026-09-22 14:29:22 +08:00
commit ce0bf42e04
45 changed files with 1463 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
"""用例数据读取:fixtures/*.yml → namedtuple 行对象。
用例数据与代码分离,读取后按字段名访问,写错字段名立刻 AttributeError:
rows = load('login') # fixtures/login.yml
rows[0].username / rows[0].result
"""
from collections import namedtuple
import yaml
from core.path import get_path
def load(name):
"""读取 fixtures/<name>.yml,返回 namedtuple 行对象列表。"""
path = get_path('fixtures', '{0}.yml'.format(name))
with open(path, encoding='utf-8') as f:
doc = yaml.safe_load(f)
rows = doc.get('cases', doc) if isinstance(doc, dict) else doc
if not rows:
return []
Row = namedtuple('Row', list(rows[0].keys()))
return [Row(*[r.get(k) for k in Row._fields]) for r in rows]