Skip to content

Commit 3bd8c8c

Browse files
committed
Respond to review comments.
1 parent e1c2eed commit 3bd8c8c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Lib/test/libregrtest/save_env.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
import sys
55
import threading
66

7-
from importlib import import_module
87
from test import support
98
from test.support import os_helper
109

1110
from .utils import print_warning
1211

12+
# Import termios to save and restore the tty. This is only available on
13+
# Unix, and it's fine if the module can't be found.
14+
try:
15+
import termios
16+
except ModuleNotFoundError:
17+
pass
18+
1319

1420
class SkipTestEnvironment(Exception):
1521
pass
@@ -73,16 +79,11 @@ def get_module(self, name):
7379
# function for restore() methods
7480
return sys.modules[name]
7581

76-
def try_get_module(self, name, *, demand=False):
82+
def try_get_module(self, name):
7783
# function for get() methods
7884
try:
7985
return self.get_module(name)
8086
except KeyError:
81-
if demand:
82-
try:
83-
return import_module(name)
84-
except ModuleNotFoundError:
85-
pass
8687
raise SkipTestEnvironment
8788

8889
def get_urllib_requests__url_tempfiles(self):
@@ -300,13 +301,12 @@ def restore_warnings_showwarning(self, fxn):
300301
warnings.showwarning = fxn
301302

302303
def get_stty_echo(self):
303-
termios = self.try_get_module('termios', demand=True)
304+
termios = self.try_get_module('termios')
304305
if not os.isatty(fd := sys.__stdin__.fileno()):
305306
return None
306307
attrs = termios.tcgetattr(fd)
307308
lflags = attrs[3]
308309
return bool(lflags & termios.ECHO)
309-
310310
def restore_stty_echo(self, echo):
311311
termios = self.get_module('termios')
312312
attrs = termios.tcgetattr(fd := sys.__stdin__.fileno())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Preserve and restore the state of ``stty echo`` as a test environment.
1+
Preserve and restore the state of ``stty echo`` as part of the test environment.

0 commit comments

Comments
 (0)