Python: a test inside a package misses imports that resolve from its basedir

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

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

從 src/repo/adapters/python.ts 中的 resolvePythonGraph 和逐檔的 fileRoots 邏輯開始。閱讀現有的 Python 圖測試,並新增一個符合 issue 中 services/api/tests 套件配置的案例,其中 test_app.py 匯入同目錄下的 app。完成標準是:變更 services/api/app.py 時會選取該測試,且端對端分析會將其回報為受影響項。

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

描述

resolvePythonGraph (src/repo/adapters/python.ts, the fileRoots line in the per-file loop) adds a file's own directory to the import roots only when that directory has no __init__.py. pytest's default prepend import mode puts the file's basedir on sys.path: the first directory above the file's package. A test inside a package below the repository root can import modules beside that package, and DiffCI misses the edge.

pyproject.toml                    [tool.pytest.ini_options]
services/api/app.py               def f(): return 1
services/api/tests/__init__.py
services/api/tests/test_app.py    import app

python -m pytest services/api/tests/test_app.py passes (pytest 9.2).

Expected: a change to services/api/app.py selects services/api/tests/test_app.py.

Actual: no edge and no blocker (app is not first-party when seen from the root), so the change is selective with no tests:

resolvePythonGraph(
  ["services/api/app.py", "services/api/tests/__init__.py", "services/api/tests/test_app.py"],
  { "services/api/app.py": { imports: [] }, "services/api/tests/__init__.py": { imports: [] },
    "services/api/tests/test_app.py": { imports: [["app", 0, []]] } },
  { pythonFiles: ["test_*.py"], testpaths: [], pythonpath: [] },
  new Set(["services/api/tests/test_app.py"]),
); // { edges: [], blockers: [] }

End to end, ImpactAnalyzer returns fallbackRequired: false and no affected tests.

Fix: resolve against the basedir: the file's directory when it is not a package, otherwise the nearest ancestor without __init__.py.

主要語言
TypeScript
星號
0
分支
4
平均合併
18 小時 41 分鐘
30 天內合併 PR
48

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

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

DiffCI/core 的其他 Issue

查看 DiffCI/core 的全部 Issue

相似的 Issue

更多 TypeScript Issue

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

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