Skip to content

Conversation

@warsaw
Copy link
Member

@warsaw warsaw commented Oct 23, 2025

The test suite sometimes turns off terminal echo after it completes. As far as I can tell, it's completely random and probably caused by tests that don't (or can't!) fully clean up after themselves. After implementing this fix and testing it many times with make test and make quicktest, I see a common set of tests that it happens in, but no real rhyme or reason.

This patch just saves and restores termios.ECHO as a saved test environment and in lots of local testing it works perfectly. Yeah, it's just an annoyance but as #140480 says, this has been annoying me for many releases. Thanks to @zware for suggesting a test environment in my abandoned #140482 PR.

I recommend backporting to all active non-security branches as it will help and there should be no risk involved. One caveat is that I did have to change the signature and semantics of try_get_module() because if the requested module is not already imported, sys.modules[name] will fail, and since termios isn't generally imported, try_get_module() would be unhelpful otherwise. The alternative is to import termios at the top of the module so it's always available, but as no other saved test environment seems to do that, and this environment is global rather than tied to a specific test, I thought this was the better approach. Suggestions welcome.

@warsaw warsaw self-assigned this Oct 23, 2025
@warsaw warsaw requested review from vstinner and zware October 23, 2025 23:53
@warsaw warsaw added tests Tests in the Lib/test dir 3.13 bugs and security fixes 3.14 bugs and security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels Oct 23, 2025
@warsaw warsaw changed the title gh-140482: Preserve and restore stty echo as a test environment gh-140480: Preserve and restore stty echo as a test environment Oct 23, 2025
@warsaw warsaw changed the title gh-140480: Preserve and restore stty echo as a test environment gh-140482: Preserve and restore stty echo as a test environment Oct 23, 2025
Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few style nits and a question, but LGTM.

@picnixz picnixz removed 3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels Oct 24, 2025
@warsaw warsaw merged commit b3c713a into python:main Oct 24, 2025
59 checks passed
@miss-islington-app
Copy link

Thanks @warsaw for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 24, 2025
…nt (pythonGH-140519)

(cherry picked from commit b3c713a)

Co-authored-by: Barry Warsaw <barry@python.org>
pythongh-140482: Restore `stty echo` as a test environment
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 24, 2025
…nt (pythonGH-140519)

(cherry picked from commit b3c713a)

Co-authored-by: Barry Warsaw <barry@python.org>
pythongh-140482: Restore `stty echo` as a test environment
@bedevere-app
Copy link

bedevere-app bot commented Oct 24, 2025

GH-140562 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Oct 24, 2025
@bedevere-app
Copy link

bedevere-app bot commented Oct 24, 2025

GH-140563 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 24, 2025
warsaw added a commit that referenced this pull request Oct 24, 2025
…ent (GH-140519) (#140563)

gh-140482: Preserve and restore `stty echo` as a test environment (GH-140519)
(cherry picked from commit b3c713a)


gh-140482: Restore `stty echo` as a test environment

Co-authored-by: Barry Warsaw <barry@python.org>
warsaw added a commit that referenced this pull request Oct 24, 2025
…ent (GH-140519) (#140562)

gh-140482: Preserve and restore `stty echo` as a test environment (GH-140519)
(cherry picked from commit b3c713a)


gh-140482: Restore `stty echo` as a test environment

Co-authored-by: Barry Warsaw <barry@python.org>
@warsaw warsaw deleted the gh140482-terminal-echo branch October 24, 2025 19:24
@vstinner
Copy link
Member

So which tests fail with this additional check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants