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.
|
|
||
| self.pyrepl_input = None | ||
| if _pyrepl_available(): | ||
| if _pyrepl_available(self.stdin, self.stdout): |
There was a problem hiding this comment.
This call is outside the existing fallback. If a custom fileno() returns an invalid type, os.isatty() can raise TypeError here. Can the color test exercise color calculation without setting up the terminal?
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
* Catch TypeError from os.isatty() for a non-int fileno(). * Test gen_colors() directly, without setting up a TTY.
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.