- 优化 WorkflowExecutor 与 Exchange支持 ExecutionEnv 资源注入。 - 实现 Session 级别连接复用与变量池内存镜像化,消除重复 I/O 开销。 - 引入 ChainMap 实现动态上下文切换,解决参数化变量与全局提取变量的优先级覆盖。 - 完善变量提取与断言逻辑,确保跨用例变量流转的可靠性。
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# coding=utf-8
|
|
|
|
"""
|
|
@desc: Pytest 配置文件,用于设置全局 Fixture 和钩子函数
|
|
"""
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
import logging
|
|
|
|
from core import settings
|
|
from commons.files import YamlFile
|
|
from core.context import VariableStore, ExecutionEnv
|
|
from core.executor import WorkflowExecutor
|
|
from core.models import RawSchema
|
|
from core.session import Session
|
|
from core.exchange import Exchange
|
|
from core.settings import EXTRACT_CACHE
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def api_env():
|
|
"""
|
|
工业级资源调度器
|
|
1. 保持全局单 Session (连接池复用)
|
|
2. 变量池 L2 内存镜像化 (减少 I/O)
|
|
"""
|
|
# Setup: 加载环境
|
|
store = VariableStore(settings.DATA_DIR / "extract.yaml")
|
|
exchanger = Exchange(variable_cache=store.store)
|
|
session = Session(settings.base_url)
|
|
executor = WorkflowExecutor()
|
|
|
|
env = ExecutionEnv(session, store, executor, exchanger)
|
|
|
|
yield env # 注入到测试用例中
|
|
|
|
# Teardown: 统一持久化与清理
|
|
store.persist()
|
|
session.close()
|
|
@pytest.fixture(scope="session")
|
|
def session():
|
|
"""全局共享的 Session Fixture"""
|
|
return Session(settings.base_url)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def exchanger():
|
|
"""全局共享的 Exchange Fixture"""
|
|
return Exchange(EXTRACT_CACHE)
|
|
|
|
|
|
# @pytest.fixture(scope="session")
|
|
# def case_engine(session, exchanger):
|
|
# """全局共享的 CaseEngine Fixture"""
|
|
# return CaseEngine(session, exchanger)
|
|
|
|
|