2025-12-09 00:36:27 +08:00
|
|
|
"""
|
|
|
|
|
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
|
2025-12-11 23:25:16 +08:00
|
|
|
async def strategy_service_client() -> AsyncIterator[AsyncClient]:
|
|
|
|
|
"""Strategy Service 测试客户端"""
|
|
|
|
|
from src.strategy_service.app import app
|
2025-12-09 00:36:27 +08:00
|
|
|
|
|
|
|
|
transport = ASGITransport(app=app)
|
|
|
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
|
|
|
yield client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest_asyncio.fixture
|
2025-12-10 00:15:19 +08:00
|
|
|
async def qmt_service_client() -> AsyncIterator[AsyncClient]:
|
|
|
|
|
"""QMT Service 测试客户端"""
|
|
|
|
|
from src.qmt_service.app import app
|
2025-12-09 00:36:27 +08:00
|
|
|
|
|
|
|
|
transport = ASGITransport(app=app)
|
|
|
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
|
|
|
yield client
|