Skip to content

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

@sendaoYan

Description

@sendaoYan

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions