test.test_pdb.PdbTestColorize.test_gen_colors fails when pyrepl is unavailable at runtime
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Description
test.test_pdb.PdbTestColorize.test_gen_colors can fail in the standard test suite (for example via make test) with:
Re-running test_pdb in verbose mode (matching: test_gen_colors)
test_gen_colors (test.test_pdb.PdbTestColorize.test_gen_colors) ... ERROR
======================================================================
ERROR: test_gen_colors (test.test_pdb.PdbTestColorize.test_gen_colors)
----------------------------------------------------------------------
Traceback (most recent call last):
File [35m"/home/yansendao/git/cpython-ysd/Lib/test/test_pdb.py"[0m, line [35m5008[0m, in [35mtest_gen_colors[0m
gen_colors = [1;31mp.pyrepl_input.gen_colors[0m
[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^[0m
[1;35mAttributeError[0m: [35m'NoneType' object has no attribute 'gen_colors'[0m
Root cause
There are two related problems:
@unittest.skipIf(not pdb._pyrepl_available()) is evaluated at import time
unittest.skipIf checks its condition when the test class is defined, not when the test runs. In regrtest worker subprocesses, sys.stdin may be a TTY at import time but is no longer suitable when the test executes, so the skip condition and runtime behavior diverge.
pdb._pyrepl_available() does not match Pdb initialization
_pyrepl_available() only consults _pyrepl.main.CAN_USE_PYREPL, which is computed once at import time. Pdb.init may still fail to create PdbPyReplInput (for example when stdin is not a TTY), silently leaving self.pyrepl_input = None.
Additionally, _pyrepl_available() always inspected sys.stdin, while Pdb uses self.stdin and self.stdout.
Steps to reproduce
time ( rm -rf build ; mkdir build ; cd build ; ../configure --prefix=$PWD/install &> configure.log ; make -j &> make.log ; make -j install &> install.log ; time make test TESTPYTHONOPTS="-s" TESTOPTS="-v -
uall,-network,-gui --junit-xml cpython.xml test_pdb" &> test_pdb.log )
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-150545
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 test/test_pdb.py 開始,特別查看 PdbTestColorize.test_gen_colors,並結合 pdb._pyrepl_available() 和 Pdb 的初始化追蹤其 skip 條件。使用報告中的測試命令重現失敗,然後驗證測試的可用性檢查是否與執行時的 Pdb 行為一致,以及在 pyrepl 無法使用時測試是否通過。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- testing-qa
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100