用途:为 LangChain 1.0 / LangGraph 1.0 项目搭建快速、确定性的本地测试循环,解决真实模型测试不确定、假模型缺少元数据、VCR 录像带泄露密钥、pytest 收集被警告中断等问题。
主要能力:用 FakeListChatModel / FakeListLLM 做确定性单元测试;通过子类 FakeChatWithUsage 合成 response_metadata['token_usage'],避免读取 token 用量的回调崩溃;用 VCR 录像带录制并重放集成测试,配合 filter_headers 过滤 Authorization、x-api-key 等敏感头,并用 pre-commit 钩子扫描 sk- / sk-ant- / Bearer 模式;在 pyproject.toml 中配置 pytest 标记与 filterwarnings 策略;用 RUN_INTEGRATION=1 环境变量门控集成测试;LangGraph 测试使用每测试独立 thread_id 与 MemorySaver,避免状态串扰。
使用方式:安装 pip install langchain-core>=1.0,<2.0 langgraph>=1.0,<2.0 pytest vcrpy pytest-recording;在 tests/conftest.py 配置假模型夹具、VCR 配置与集成测试门控;录制录像带用 pytest --record-mode=once tests/,其余运行重放;默认 pytest 只跑单元测试,夜间或手动用 RUN_INTEGRATION=1 pytest -m integration。
适用场景:链式调用形状、解析器、路由逻辑的单元测试;端到端链行为与提供商边界情况的录像带重放测试;夜间冒烟与提供商回归测试。
限制:需要 Python 3.10+ 与 pyproject.toml;集成测试需至少一个提供商密钥;Anthropic temperature=0 仍会采样,不能保证确定性;录像带需提交并保持更新,请求形状变化时需重新录制;资料未提供具体收费、价格或平台信息。