GeezerVison is showing github.com — Test suite sometimes leaves terminal in -echo · Issue #140482 · python/cpython
Test suite sometimes leaves terminal in -echo #140482DescriptionBug report
Bug description:
Sometimes running make test or make quicktest leaves the terminal in -echo mode, which means that after the test suite runs to completion, no keyboard input is echoed until you do a stty echo.
I've seen this in Python major version branches going back many releases, but I've just sighed, reset my terminal, and moved on. I actually spent a little bit of time trying to debug the problem, but with little success. It definitely happens in the 3.13, 3.14, and cpython (3.15 dev) branches.
It happens only intermittently, so it's not reproducible. The linked branch above has my debug code in it, but even that hasn't really helped me narrow down the offending test. The best I could come up with is test_ssl because that also fails intermittently, and when it fails, it seems to leave the terminal in -echo, but the correlation isn't perfect. I.e. in pristine main branch, you get both echo and -echo when the full suite passes, or when test_ssl fails.
Tested on macOS only, in Terminal.app and iTerm2. I've tried to reproduce it on a Linux VM, but haven't been able to. I suspect there's some timing issue where one of the terminal-munging tests runs in a subprocess and doesn't get reset at the right time.
Anyway, it's just an annoyance since the fix is easy: stty echo (which you have to type blind). Still I wanted to capture what I know in case anyone else has seen this and/or can make more progress on fixing it.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Reacted by Bartosz Sławecki Activitycolesbury commented on Nov 24, 2025 I am frequently seeing warnings when running make test on Linux that stty_echo was modified. They seem to happen in random tests:
0:00:02 load avg: 24.12 [153/497/1] test.test_future_stmt.test_future_single_import failed (env changed)
test_floor_div_operator (test.test_future_stmt.test_future_single_import.TestFuture.test_floor_div_operator) ... ok
test_nested_scopes (test.test_future_stmt.test_future_single_import.TestFuture.test_nested_scopes) ... ok
test_true_div_as_default (test.test_future_stmt.test_future_single_import.TestFuture.test_true_div_as_default) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.000s
OK
Warning -- stty_echo was modified by test.test_future_stmt.test_future_single_import
Warning -- Before: True
Warning -- After: False
colesbury commented on Nov 25, 2025 This new behavior is much more annoying that the previous problems with -echo. Now the test suite is flaky, takes longer to run due to retries, and it's harder to tell if a local change introduced a bug because of all the spurious ENV CHANGED failures. chris-eibl commented on Dec 2, 2025
It definitely happens in the 3.13, 3.14, and cpython (3.15 dev) branches.
If this happens beginning with 3.13, I have a gut feeling that it might be related to the PyRepl tests.
FWIW, I've faced a wierd / broken terminal on Windows after running the tests until I've introduced a missing con.restore() at the end of test_multiline_ctrl_z (https://github.com/python/cpython/pull/132440/files#r2051688227) - and it depended on the order in which the tests were performed.
Having a closer look at test_unix_console.py, in
|
def test_getheightwidth_with_invalid_environ(self, _os_write): |
|
# gh-128636 |
|
console = UnixConsole(term="xterm") |
|
with os_helper.EnvironmentVarGuard() as env: |
|
env["LINES"] = "" |
|
self.assertIsInstance(console.getheightwidth(), tuple) |
|
env["COLUMNS"] = "" |
|
self.assertIsInstance(console.getheightwidth(), tuple) |
|
os.environ = [] |
|
self.assertIsInstance(console.getheightwidth(), tuple) |
|
|
the console is not restored. If this happens to be the last test executed, maybe this can be an explanation for the problems you are facing?
Also, if any of those tests fail, the console won't be restored and IMHO that could be assured with e.g. a context manager, try/finally, etc? colesbury commented on Dec 2, 2025 I modified the test runner so that it polls termios.tcgetattr while the tests are running and tried to narrow things down by running the tests one at a time. On Linux, the only test that I found that disabled echo was test_pty.test_spawn_doesnt_hang. I have a tentative fix:
warsaw commented on Dec 3, 2025
This new behavior is much more annoying that the previous problems with -echo. Now the test suite is flaky, takes longer to run due to retries, and it's harder to tell if a local change introduced a bug because of all the spurious ENV CHANGED failures.
I'm not sure it's fair to say the test suite is flaky with the change, because I think it was always flaky, it's just that the flakiness was mostly hidden except for the annoying echo behavior. Although I didn't find the test you mentioned, I did see the env changes come up seemingly randomly, so couldn't narrow it down. Glad you were able to!
I modified the test runner so that it polls termios.tcgetattr while the tests are running
I didn't see that in the PR -- is it worth keeping that debugging code (maybe even commented out?). colesbury commented on Dec 3, 2025
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|