QTrade/tests/conftest.py
cuizhan eb2179809f 重构:统一策略框架和服务命名,修复所有Pylance错误
主要改动:
1. 策略框架重构
   - 统一实盘和回测策略接口
   - 新增 src/core/strategy/ 核心策略模块
   - BaseStrategy、Signal、StrategyContext 统一定义
   - 内置指标库(TA-Lib封装)和策略注册中心
   - 删除旧策略代码

2. 服务重命名
   - strategy_engine -> strategy_service (统一 _service 后缀)
   - 更新所有配置、导入路径、测试文件
   - 23个文件同步更新

3. 回测服务增强
   - 支持多策略-多股票组合回测
   - 为每个策略-股票组合创建独立管理器
   - BacktestConfig schema 添加 strategy_id 字段
   - 数据回放器支持独立频道

4. 代码质量提升
   - 修复所有 src/ 目录下的 Pylance 错误
   - 添加 get_kline_model 函数
   - 修复 K线字段名(trade_date -> time)
   - 修复类型转换(Decimal -> float)
   - 修复 MA_Type 导入路径
   - 统一代码风格
2025-12-11 23:25:16 +08:00

69 lines
1.9 KiB
Python

"""
Pytest 配置和共享 fixtures
"""
import asyncio
from typing import AsyncIterator, Generator
import pytest # type: ignore
import pytest_asyncio # type: ignore
from httpx import AsyncClient, ASGITransport # type: ignore
@pytest.fixture(scope="session")
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
"""创建事件循环"""
loop = asyncio.new_event_loop()
yield loop
loop.close()
@pytest_asyncio.fixture
async def gateway_client() -> AsyncIterator[AsyncClient]:
"""Gateway 测试客户端"""
from src.gateway.app import app
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client
@pytest_asyncio.fixture
async def core_service_client() -> AsyncIterator[AsyncClient]:
"""Core Service 测试客户端"""
from src.core_service.app import app
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client
@pytest_asyncio.fixture
async def data_service_client() -> AsyncIterator[AsyncClient]:
"""Data Service 测试客户端"""
from src.data_service.app import app
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client
@pytest_asyncio.fixture
async def strategy_service_client() -> AsyncIterator[AsyncClient]:
"""Strategy Service 测试客户端"""
from src.strategy_service.app import app
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client
@pytest_asyncio.fixture
async def qmt_service_client() -> AsyncIterator[AsyncClient]:
"""QMT Service 测试客户端"""
from src.qmt_service.app import app
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client