QTrade/tests/conftest.py

69 lines
1.9 KiB
Python
Raw Permalink Normal View History

"""
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