Repository navigation
Test suite sometimes leaves terminal in -echo #140482
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortestsTests in the Lib/test dirTests in the Lib/test dir3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes
on Oct 22, 2025 I am frequently seeing warnings when running
make teston 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: FalseThis 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.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 missingcon.restore()at the end oftest_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
cpython/Lib/test/test_pyrepl/test_unix_console.py
Lines 302 to 312 in 8801c6d
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?
- added a commit that references this issue
on Dec 2, 2025 I modified the test runner so that it polls
termios.tcgetattrwhile 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 wastest_pty.test_spawn_doesnt_hang. I have a tentative fix:Reacted by Chris EiblThis 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.tcgetattrwhile the tests are runningI didn't see that in the PR -- is it worth keeping that debugging code (maybe even commented out?).
Here is the debug code that I'm using: https://gist.github.com/colesbury/639671ae1254a406ab72fa351e389a63
It's messy and also causes occasional test failures itself, so I don't think it's worth commiting.
Bug report
Bug description:
Sometimes running
make testormake quicktestleaves the terminal in-echomode, which means that after the test suite runs to completion, no keyboard input is echoed until you do astty 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_sslbecause 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 pristinemainbranch, you get bothechoand-echowhen the full suite passes, or whentest_sslfails.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
stty echoas a test environment #140519stty echoas a test environment (GH-140519) #140562stty echoas a test environment (GH-140519) #140563stty echoas a test environment (#140519) #142196