conftest.py 1.2 KB

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