Files
InterfaceAutoTest/test_cases/test_collector.py
CNWei d05757f7cc feat(core): 增强 Exchange,实现智能变量替换与类型保持
- 优化 conftest.py 增加异常日志记录和测试报告环境信息
 - 其他优化
2026-03-16 19:15:01 +08:00

31 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# coding=utf-8
import logging
from core import settings
from core.creator import CaseGenerator, TestTemplateBase
logger = logging.getLogger(__name__)
class TestRunner(TestTemplateBase):
"""
测试用例的动态容器 (Test Case Container)。
这是一个占位符类CaseGenerator 会扫描所有的 YAML 用例文件,
然后将每一个用例动态地生成为一个测试方法并挂载到这个类上。
Pytest 最终会发现并执行这些动态挂载的 test_* 方法。
"""
pass
try:
# --- 核心逻辑:动态生成测试用例 ---
# 当 Pytest 在“收集测试用例”阶段加载此模块时,下面的代码会立即执行。
logger.info("--- [Collector] 开始扫描并动态生成测试用例 ---")
CaseGenerator.build_and_register(target_cls=TestRunner, cases_dir=settings.TEST_CASE_DIR)
logger.info(f"--- [Collector] 测试用例生成完毕,已成功加载到 {TestRunner.__name__} ---")
except Exception as e:
logger.critical(f"--- [Collector] 动态生成测试用例时发生致命错误,测试执行中止 ---", exc_info=True)
# 抛出异常,让 pytest 捕获并报告为收集错误 (Collection Error)
raise RuntimeError("测试用例收集失败,请检查日志中的详细错误信息。") from e