69 lines
1.9 KiB
Python
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_adapter_client() -> AsyncIterator[AsyncClient]:
|
||
|
|
"""QMT Adapter 测试客户端"""
|
||
|
|
from src.qmt_adapter.app import app
|
||
|
|
|
||
|
|
transport = ASGITransport(app=app)
|
||
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||
|
|
yield client
|