فهرست منبع

test(B-74): langgraph conftest 显式 init_checkpointer + pytest-asyncio loop scope(auto_tag 5 例自 checkpointer 500 转 LLM 断言,权威验证在 251)

E2E Test Bot 4 روز پیش
والد
کامیت
3f4b4bcac3
2فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 7 0
      cfc-langgraph/pyproject.toml
  2. 12 0
      cfc-langgraph/tests/conftest.py

+ 7 - 0
cfc-langgraph/pyproject.toml

@@ -34,3 +34,10 @@ target-version = "py311"
 line-length = 100
 select = ["E", "F", "I", "N", "W"]
 ignore = ["E501"]
+
+[tool.pytest.ini_options]
+# pytest-asyncio 1.x 要求显式 loop scope;B-74 修复(2026-11-09):
+# session 级 autouse async fixture(conftest._init_checkpointer_global)需
+# session/auto 默认 loop scope 方能初始化 checkpointer 并无缝复用于全部测试。
+asyncio_mode = "auto"
+asyncio_default_fixture_loop_scope = "session"

+ 12 - 0
cfc-langgraph/tests/conftest.py

@@ -12,6 +12,18 @@ 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)