tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env vars

未關閉 適合新手
#1,976 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@Mathoholic 已經在處理了。

開始於 2026年10月11日。

  • #1979 來自 @Mathoholic —— 未關閉
  • #2072 來自 @AsherLucas —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
80/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
testing

研究方向

失敗的設定是 tests/unit/test_prompt.py:132 的 langfuse fixture,它不帶參數呼叫 Langfuse()。取消設定 LANGFUSE_* 變數並執行 uv run --frozen pytest tests/unit/test_prompt.py -q 來重現,然後與 .github/workflows/ci.yml:65-67 中的工作層級環境變數進行比較。完成標準是:在沒有環境變數的情況下 18 個錯誤消失,或者 CONTRIBUTING.md 記載了所需的匯出變數。在編輯之前,請與維護者確認他們偏好兩個建議修正方案中的哪一個。

由索引模型根據 Issue 內容生成。

描述

bug feat-prompt-management sdk-python

CONTRIBUTING.md says unit tests don't require a running Langfuse server, but on a fresh clone with no LANGFUSE_* env vars set, 18 tests in tests/unit/test_prompt.py error during fixture setup:

AttributeError: Langfuse client is not initialized
langfuse/_client/client.py:497

The langfuse fixture (tests/unit/test_prompt.py:132) calls Langfuse() with no arguments. Without LANGFUSE_PUBLIC_KEY, the client initializes as disabled (_resources is None), so the api setter raises when the fixture assigns Mock().

Repro (latest main):

uv sync --locked
env -u LANGFUSE_PUBLIC_KEY -u LANGFUSE_SECRET_KEY -u LANGFUSE_BASE_URL \
  uv run --frozen pytest tests/unit/test_prompt.py -q
# 8 passed, 18 errors

With dummy keys exported, all 26 pass (full tests/unit: 885 passed).

This passes in CI because the unit-test job sets LANGFUSE_PUBLIC_KEY=pk-lf-test, LANGFUSE_SECRET_KEY=sk-lf-test and LANGFUSE_BASE_URL=http://localhost:3000 at the job level (.github/workflows/ci.yml:65-67), so the gap only shows up locally.

Proposed fix (either works, happy to go with whichever you prefer):

  1. Pass the same dummy credentials CI uses explicitly in the fixture, e.g. Langfuse(public_key="pk-lf-test", secret_key="sk-lf-test", base_url="http://localhost:3000"), so tests/unit is self-contained as CONTRIBUTING.md describes.
  2. Or, if relying on env vars is intentional, add a note to CONTRIBUTING.md telling contributors to export these values before running unit tests.

Happy to open a PR if this is welcome.

主要語言
Python
星號
504
分支
391
平均合併
1 天 3 小時
30 天內合併 PR
74

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

langfuse/langfuse-python 的其他 Issue

查看 langfuse/langfuse-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。