Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFire
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 85/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 冷清
- 技術堆疊
- python
- 領域
- testing-qa
研究方向
從 fire/main_test.py 中的 MainModuleTest.testArgPassing 和 MainModuleFileTest.setUp/testFileNameFire 開始,然後使用 pytest 執行 Windows 測試套件。檢查現有 PR #679 中關於 regex 失敗的內容,並驗證暫存檔案可以在匯入期間重新開啟。Windows 和 POSIX 上的全部 261 個測試都通過即表示完成。
由索引模型根據 Issue 內容生成。
描述
On a fresh clone on Windows, the test suite fails 2 of 261 tests, both in fire/main_test.py and both Windows-specific. CI currently runs macos-latest + ubuntu-latest only, so neither can be caught there.
FAILED fire/main_test.py::MainModuleTest::testArgPassing - re.PatternError: bad escape \p at position 5
FAILED fire/main_test.py::MainModuleFileTest::testFileNameFire - PermissionError: [Errno 13] Permission denied: 'C:\\...\\tmponwjvj2u.py'
2 failed, 259 passed in 6.30s
Environment: Windows 11, Python 3.13.13, pip install -e . pytest hypothesis, clone at current master.
1. testArgPassing — unescaped path in a regex. assertOutputMatches treats its argument as a regex, and the test interpolates os.path.join('part1', 'part2', 'part3') unescaped. On Windows that's part1\part2\part3, and \p has been a hard error (re.PatternError) since Python 3.12. POSIX never sees it because / needs no escaping. The open PR #679 fixes exactly this with re.escape(); applying its change locally takes the suite to 1 failed / 260 passed, so it would be lovely to see it merged.
2. testFileNameFire — NamedTemporaryFile can't be reopened while open on Windows. MainModuleFileTest.setUp keeps the temp .py file open, and fire.__main__.import_from_file_path → exec_module then opens it a second time for import. That second open is the documented Windows limitation of NamedTemporaryFile ("the name cannot be used to open the file a second time while it is still open"), and it surfaces as PermissionError inside the import machinery. This is test-harness-only: python -m fire somefile.py itself works fine on Windows.
Fix I verified locally for (2) — with it (plus #679's change), the whole suite passes on this machine, 261 passed in 1.65s, and it stays green on POSIX semantics:
def setUp(self):
super().setUp()
- self.file = tempfile.NamedTemporaryFile(suffix='.py') # pylint: disable=consider-using-with
+ self.file = tempfile.NamedTemporaryFile(suffix='.py', delete=False) # pylint: disable=consider-using-with
self.file.write(b'class Foo:\n def double(self, n):\n return 2 * n\n')
- self.file.flush()
+ self.file.close()
+ self.addCleanup(os.unlink, self.file.name)
- self.file2 = tempfile.NamedTemporaryFile() # pylint: disable=consider-using-with
+ self.file2 = tempfile.NamedTemporaryFile(delete=False) # pylint: disable=consider-using-with
+ self.file2.close()
+ self.addCleanup(os.unlink, self.file2.name)
(delete_on_close=False would be tidier but is 3.12+, and setup.py still advertises 3.7 support.)
I'm reporting this as an issue rather than sending the patch because I haven't signed the Google CLA yet. Happy for anyone — including the author of #679 — to fold the diff above into a PR. Also happy to follow up with a windows-latest line for the CI matrix discussion if that's of interest, though I understand that's a bigger decision than these two fixes.
- 主要語言
- Python
- 星號
- 28.2k
- 分支
- 1.5k
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
google/python-fire 的其他 Issue
-
WrappedJoin adds an empty line before an oversized first item可能已有人在做 @GreedyC 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
google/python-fire#705 ·
-
Brace-based template arguments crash literal parsing with TypeError可能已有人在做 @codewithfourtix 於 2 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
google/python-fire#703 ·
-
Release 0.7.2?未關閉
難度 3/5 1-2 天 新手友好度 38/100
google/python-fire#698 ·
-
Uncaught exception when a component has a property whose getter raises (intended?)可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 3/5 1-2 天 新手友好度 58/100
google/python-fire#672 · 5 則留言 ·
-
python-fire: (1) PAGER+shell=True RCE in console_io.More (2) bash $(...) runs when sourcing --completion from maliciously named .py file. PoC verified.可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 4/5 3-5 天 新手友好度 45/100
google/python-fire#665 · 2 則留言 ·
查看 google/python-fire 的全部 Issue
相似的 Issue
-
Zero-token evaluations are treated as missing cost in selection可能已有人在做 @sylvesterkaczmarek 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
google-research/rrsi#6 ·
-
bug
難度 2/5 1-3 小時 新手友好度 88/100
aws-samples/sample-aws-genai-db-modernizer#294 ·
維護者通常 1 天內回覆
-
feedback simulation workshop
難度 2/5 1-3 小時 新手友好度 84/100
githubnext/gh-aw-workshop#4174 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 86/100
WingedGuardian/GENesis-AGI#2852 ·
維護者通常 1 天內回覆
-
camlight produces degenerate target camera and light frames可能已有人在做 @kavyabhand 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
google-deepmind/mujoco_warp#1743 ·
維護者通常 1 天內回覆