feat(core): 增强 Exchange,实现智能变量替换与类型保持
- 优化 conftest.py 增加异常日志记录和测试报告环境信息 - 其他优化
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
@desc:
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, Any
|
||||
from typing import Any
|
||||
from pathlib import Path
|
||||
|
||||
from core.exchange import Exchange
|
||||
@@ -25,7 +25,7 @@ class VariableStore:
|
||||
self.seed_file = seed_file
|
||||
self.processor = YamlProcessor(seed_file)
|
||||
# 启动时仅加载一次
|
||||
self.store: Dict[str, Any] = self.processor.load() or {}
|
||||
self.store: dict[str, Any] = self.processor.load() or {}
|
||||
|
||||
def persist(self):
|
||||
"""测试结束时统一写盘"""
|
||||
|
||||
@@ -14,6 +14,8 @@ import logging
|
||||
import allure
|
||||
from pathlib import Path
|
||||
from dataclasses import dataclass
|
||||
|
||||
from conftest import execution_context
|
||||
from core import settings
|
||||
from core.executor import WorkflowExecutor
|
||||
from pydantic import ValidationError
|
||||
@@ -142,7 +144,7 @@ class CaseGenerator:
|
||||
method_name = f"test_{index:03d}_{safe_title}"
|
||||
print(method_name)
|
||||
setattr(target_cls, method_name, dynamic_test_method)
|
||||
print(target_cls.__dict__)
|
||||
# print(target_cls.__dict__)
|
||||
logger.debug(f"Successfully registered: {method_name}")
|
||||
|
||||
@staticmethod
|
||||
@@ -150,8 +152,7 @@ class CaseGenerator:
|
||||
"""封装具体的 pytest 执行节点"""
|
||||
case_template = entity.step_data
|
||||
context = entity.row_context
|
||||
|
||||
def build_actual_case(instance: TestTemplateBase, api_env):
|
||||
def build_actual_case(instance: TestTemplateBase, execution_context):
|
||||
# --- 1. 动态设置 Allure 报告属性 ---
|
||||
|
||||
allure.dynamic.epic(case_template.epic or settings.allure_epic)
|
||||
@@ -161,7 +162,7 @@ class CaseGenerator:
|
||||
# 日志记录 (利用 instance 标注来源)
|
||||
logger.info(f"[Runner] Class: {instance.__class__.__name__} | Case: {title}")
|
||||
try:
|
||||
WorkflowExecutor.perform(case_template, api_env, context=context)
|
||||
WorkflowExecutor.perform(case_template, execution_context, context=context)
|
||||
|
||||
except Exception as e:
|
||||
# 可以在这里记录更详细的运行上下文快照
|
||||
@@ -176,4 +177,4 @@ if __name__ == '__main__':
|
||||
|
||||
# print(CaseDataLoader.get_all_cases(TEST_CASE_DIR))
|
||||
# --- 引导执行 ---
|
||||
CaseGenerator.build_and_register(TestTemplateBase, settings.TEST_CASE_DIR)
|
||||
CaseGenerator.build_and_register(TestTemplateBase, settings.TEST_CASE_DIR)
|
||||
@@ -139,4 +139,4 @@ class WorkflowExecutor:
|
||||
rendered_validate_list = env.exchanger.replace(raw_validate_list)
|
||||
# 重新通过 Adapter 触发类型修复 (str -> int)
|
||||
final_validate_data = VALIDATE_LIST_ADAPTER.validate_python(rendered_validate_list)
|
||||
CaseValidator.validate(resp, final_validate_data)
|
||||
CaseValidator.validate(resp, final_validate_data)
|
||||
Reference in New Issue
Block a user