implement pseudo tty on stdout/stderr #2711
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for contribution
Please, make sure you address all the checklists (for details on how see
development documentation)!
tox -e fix)docs/changelogfolderptyThis is my first attempt at fixing #1773, starting with the example code posted on that issue, and adapting it for some changes that have occured since then.
For the most part the code worked really nice already.
I did encounter the one problem mentioned after setting the Popen
stdoutandstderrhandles to pty:After lots of poking around, I determine that the code in
SyncWrite, which is supposed to write the content to the target after some minimum delay, was not restarting its timer appropriately, causing the output to "hang" untilSyncWritediscovered a newline\n.With that fix in 9b06df5, everything seems to be working fine, EXCEPT, the log files now have ANSI escape sequences in them... which may or may not be desirable. After all, that is what the program output.
After this patch, colored output and interactive use (
pdb,ipython) appears to be working out of the box!Testing
Here's my "human" test file with 4 cases, to exemplify the differences between tox 3, tox 4, and this patch.
I've made these sort of non-scientific comparisons on a macOS 10.15 machine.
tox 3 ("current behavior" expected by users)
pypytestF, and redFailed:texttextualvim: fully interactive, working as expectedtox 3 (Using
teeto pipe the output to a log file)py<enter>)pytesttextualvim: fully interactive, working as expected (also surprising)tox 4 ("new behavior" shows some regression in expected functionality)
py<enter>shows previous output)pytesttextualvimgtandgTcan sometimes trigger a refresh).tox 4 (Using
teeto pipe the output to a log file)py: no change usingteepytest: no change usingteetextual: behaves like tox 3 withteevim: no change usingteetox 4 with this patch!
pypytestF, and redFailed:texttextualvim: fully interactive, working as expectedtox 4 with this patch! (Using
teeto pipe the output to a log file)pySyncWritefix at work)pytesttextual: behaves like tox 3 withteevim: fully interactive, working as expected (again, not sure how, but i'll take it)TODO
Failing test to investigateturned out to be a macOS issue with homebrew-installed python interpreters. The test was expecting the executable to be/usr/local/opt/python@3.11/bin/python3.11, but when it runs throught the virtualenv, the path name comes out as/usr/local/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/bin/python3.11... These are both hardlinks to the same inode. Not reproducing on linux.Additional test coverage for this featureadded to existingtest_local_subprocess_ttyTesting on other platforms: