Repository navigation
Conversation
|
/touch |
|
Are you able to make the repro easier and more targeted? You mean the testing system somehow swapped |
Thanks for pushing on this — I dug in, and my earlier description was wrong: The trigger is
Minimal repro (run it from a terminal, so stdin is a TTY): $ ./python -c 'import io, sys, pdb; sys.stdout = io.StringIO(); print(pdb.Pdb().pyrepl_input, file=sys.__stdout__)'
NoneOr with regrtest — the junit flag is the only difference: $ ./python -m test test_pdb -m test_gen_colors # passes
$ ./python -m test test_pdb -m test_gen_colors --junit-xml /tmp/x.xml # errorsOn the pyrepl side: those tests don't read the ambient stdin/stdout from So for test_gen_colors there are two options:
Do you have a preference? Either way I'll correct the issue text, which |
The previous wording blamed sys.stdin, but the trigger is sys.stdout being replaced by unittest's output buffering with --junit-xml.
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:
Root cause
With
--junit-xml, regrtest builds its runner withcapture_output=True(
Lib/test/libregrtest/single.py), which meansTextTestRunner(buffer=True).Unittest's
TestResult._setupStdout()then replacessys.stdout(andsys.stderr) with anio.StringIOfor the duration of each test.pdb.Pdb()picks up that stream asself.stdout,PdbPyReplInput.__init__calls
stdout.fileno(), and the resultingio.UnsupportedOperationisswallowed by
Pdb.__init__, leavingpyrepl_input = None.sys.stdinis not modified and is still a TTY, so the import-time@unittest.skipIf(not pdb._pyrepl_available())keeps the test enabled eventhough pyrepl cannot be used at runtime.
Changes
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
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.