| 12345678910111213141516171819202122232425262728293031323334353637 |
- # 兼容旧版系统 sqlite3 (<3.35):chromadb 需要更高版本。
- # 仅测试环境生效(conftest 不参与生产加载);若系统已装新版 sqlite3 可移除。
- try:
- import pysqlite3
- import sys
- sys.modules["sqlite3"] = pysqlite3
- except ImportError:
- pass
- import pytest
- from httpx import AsyncClient, ASGITransport
- from app.main import app
- @pytest.fixture(scope="session", autouse=True)
- async def _init_checkpointer_global():
- """B-74 修复(2026-11-09):httpx.ASGITransport 直连不触发 FastAPI
- @app.on_event("startup"),导致 app/checkpointer.py 的 init_checkpointer()
- 从未执行、全局单例保持 None,凡走 graph 的用例(test_auto_tag×5 /
- test_chat×1)恒 500。session 级 autouse fixture 在任何用例前显式初始化
- checkpointer(init_checkpointer 幂等,已初始化则直接返回,不影响生产)。"""
- from app.checkpointer import init_checkpointer
- await init_checkpointer()
- yield
- @pytest.fixture
- async def client():
- transport = ASGITransport(app=app)
- async with AsyncClient(transport=transport, base_url="http://test") as ac:
- yield ac
- @pytest.fixture
- async def health_response(client):
- resp = await client.get("/health")
- return resp
|