python / python/cpython

test.test_pdb.PdbTestColorize.test_gen_colors fails when pyrepl is unavailable at runtime

Open
#150,544 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tests type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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 "/home/yansendao/git/cpython-ysd/Lib/test/test_pdb.py", line 5008, in test_gen_colors
    gen_colors = p.pyrepl_input.gen_colors
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'gen_colors'

test_pdb.log

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with test/test_pdb.py, especially PdbTestColorize.test_gen_colors, and trace its skip condition alongside pdb._pyrepl_available() and Pdb initialization. Reproduce the failure with the reported test command, then verify that the test's availability check matches runtime Pdb behavior and that the test passes when pyrepl is unavailable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.