From 4de36318ad018beab032c088441b0b3696549b53 Mon Sep 17 00:00:00 2001 From: johnslavik Date: Sun, 7 Dec 2025 02:19:10 +0100 Subject: [PATCH 1/2] Isolate tests from personal Readline init files using `INPUTRC=/dev/null` trick --- Lib/test/support/pty_helper.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/support/pty_helper.py b/Lib/test/support/pty_helper.py index 6587fd40333c51..7b754891fc02ee 100644 --- a/Lib/test/support/pty_helper.py +++ b/Lib/test/support/pty_helper.py @@ -10,11 +10,22 @@ from test.support.import_helper import import_module -def run_pty(script, input=b"dummy input\r", env=None): +def run_pty(script, input=b"dummy input\r", env=None, readline=None): pty = import_module('pty') output = bytearray() [master, slave] = pty.openpty() args = (sys.executable, '-c', script) + + if readline is None: + readline = "readline" in sys.modules + if readline: + # Isolate readline from personal init files by setting INPUTRC + # to an empty file. See also GH-142353. + if env is None: + env = {**os.environ.copy(), "INPUTRC": os.devnull} + else: + env.setdefault("INPUTRC", os.devnull) + proc = subprocess.Popen(args, stdin=slave, stdout=slave, stderr=slave, env=env) os.close(slave) with ExitStack() as cleanup: From 1c6153acb76280bc598ee6fe4837a30e0ad1286b Mon Sep 17 00:00:00 2001 From: johnslavik Date: Thu, 11 Dec 2025 19:18:29 +0100 Subject: [PATCH 2/2] Remove readline logic (it is unnecessary) Co-authored-by: Victor Stinner --- Lib/test/support/pty_helper.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Lib/test/support/pty_helper.py b/Lib/test/support/pty_helper.py index 7b754891fc02ee..dbe7fa429096fc 100644 --- a/Lib/test/support/pty_helper.py +++ b/Lib/test/support/pty_helper.py @@ -10,21 +10,18 @@ from test.support.import_helper import import_module -def run_pty(script, input=b"dummy input\r", env=None, readline=None): +def run_pty(script, input=b"dummy input\r", env=None): pty = import_module('pty') output = bytearray() [master, slave] = pty.openpty() args = (sys.executable, '-c', script) - if readline is None: - readline = "readline" in sys.modules - if readline: - # Isolate readline from personal init files by setting INPUTRC - # to an empty file. See also GH-142353. - if env is None: - env = {**os.environ.copy(), "INPUTRC": os.devnull} - else: - env.setdefault("INPUTRC", os.devnull) + # Isolate readline from personal init files by setting INPUTRC + # to an empty file. See also GH-142353. + if env is None: + env = {**os.environ.copy(), "INPUTRC": os.devnull} + else: + env.setdefault("INPUTRC", os.devnull) proc = subprocess.Popen(args, stdin=slave, stdout=slave, stderr=slave, env=env) os.close(slave)