Skip to content

Test suite sometimes leaves terminal in -echo #140482

Description

@warsaw

Bug 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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    3.13only security fixes
    3.14bugs and security fixes
    3.15pre-release feature fixes, bugs and security fixes
    on Oct 22, 2025
  2. added 2 commits that reference this issue on Oct 23, 2025
  3. added 2 commits that reference this issue on Oct 24, 2025
  4. added 2 commits that reference this issue on Oct 24, 2025
  5. colesbury commented on Nov 24, 2025

    @colesbury
    Contributor

    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
    
  6. colesbury commented on Nov 25, 2025

    @colesbury
    Contributor

    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.

  7. added a commit that references this issue on Dec 2, 2025
  8. chris-eibl commented on Dec 2, 2025

    @chris-eibl
    Member

    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?

  9. added a commit that references this issue on Dec 2, 2025
  10. colesbury commented on Dec 2, 2025

    @colesbury
    Contributor

    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:

  11. warsaw commented on Dec 3, 2025

    @warsaw
    MemberAuthor

    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?).

  12. added a commit that references this issue on Dec 3, 2025
  13. added 2 commits that reference this issue on Dec 3, 2025
  14. colesbury commented on Dec 3, 2025

    @colesbury
    Contributor

    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.

  15. added 2 commits that reference this issue on Dec 5, 2025
  16. added 2 commits that reference this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesOS-mactestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions