QTrade/tests/conftest.py
cuizhan 1bc3c99482 refactor: 简化服务架构 - 统一HTTP服务模式
- 新增 BaseApp 基类,统一 FastAPI 应用生命周期管理
- 移除 Gateway 服务,各服务直接对外提供 HTTP 接口
- 重命名 qmt_adapter 为 qmt_service
- 移除各服务独立的 health.py,统一由 BaseApp 提供
- 新增 scripts/init_db.py 数据库初始化脚本
- 新增 scripts/download_kline.py K线数据下载示例
- 删除 console 模块(暂不使用)
- 更新 .gitignore 忽略 caches/ 和 learning_materials/
2025-12-10 00:15:19 +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_engine_client() -> AsyncIterator[AsyncClient]:
"""Strategy Engine 测试客户端"""
from src.strategy_engine.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