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.
|
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.
gaogaotiantian
left a comment
There was a problem hiding this comment.
You have 2 news entry now - I think you should only have one. If the change is about the library and you just add regression tests, you don't need to create a news entry in Tests.
* Merge the duplicated _pyrepl_available() test blocks, using parenthesized context managers. * Keep the import-time skipIf for PdbTestReadlinePyREPL: those tests run in pty subprocesses and do not depend on the ambient stdio. * Drop the Tests NEWS entry; the Library entry covers the fix.
Done — dropped the |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @pablogsal: please review the changes made to this pull request. |
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.