"""测试基座:httpx ASGITransport 进程内测试,不起真实服务。 需要本地 27017 有 mongo;测试库 app_test,与开发库隔离。 """ import os import pytest_asyncio from httpx import ASGITransport, AsyncClient os.environ.setdefault("MONGO_DB", "app_test") from src.main import create_app @pytest_asyncio.fixture async def client(): app = create_app() async with AsyncClient( transport=ASGITransport(app=app), base_url="http://test" ) as ac: # 手动触发 lifespan(ASGITransport 不自动跑 lifespan) async with app.router.lifespan_context(app): yield ac