Skip to content

gh-150544: Fix pdb _pyrepl_available() and make test_gen_colors skip at runtime#150545

Open
sendaoYan wants to merge 3 commits into
python:mainfrom
sendaoYan:gh-150544
Open

gh-150544: Fix pdb _pyrepl_available() and make test_gen_colors skip at runtime#150545
sendaoYan wants to merge 3 commits into
python:mainfrom
sendaoYan:gh-150544

Conversation

@sendaoYan
Copy link
Copy Markdown
Contributor

Summary

Fix pdb._pyrepl_available() so it checks the actual stdin/stdout streams (including TTY and fileno() support), not only the import-time CAN_USE_PYREPL flag.
Pass self.stdin and self.stdout from Pdb.init into _pyrepl_available().
Update test_gen_colors and PdbTestReadlinePyREPL to evaluate pyrepl availability at test runtime instead of via import-time @unittest.skipIf.
Harden test_pyrepl_available with explicit mock streams.
Fixes gh-150544

Problem

test.test_pdb.PdbTestColorize.test_gen_colors could fail with:

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

Changes

  • Lib/pdb.py

Extend _pyrepl_available(stdin=None, stdout=None) to:
honor PYTHON_BASIC_REPL and CAN_USE_PYREPL
verify stdin is a TTY at call time
verify both streams support fileno()
handle fake stdin objects (e.g. doctest FakeInput) without raising
Call _pyrepl_available(self.stdin, self.stdout) from Pdb.init

  • Lib/test/test_pdb.py

test_gen_colors: replace import-time @skipIf with runtime skipTest when pyrepl or pyrepl_input is unavailable
PdbTestReadlinePyREPL: use setUpClass for runtime skipping
test_pyrepl_available: test TTY and non-TTY cases using mock streams

Testing

All the cpython tests shows this PR do not cause new fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant