test.test_pdb.PdbTestColorize.test_gen_colors fails when pyrepl is unavailable at runtime
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- 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