From 588f671eb304fbdf74d952fd78544a80917ad9ba Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 7 Aug 2026 22:54:19 +0200 Subject: [PATCH] gh-155358: Use named attributes with test.support.script_helper Replace assert_python_ok() result: * proc[0] => proc.rc * proc[1] => proc.out * proc[2] => proc.err --- Lib/test/test_calendar.py | 3 ++- Lib/test/test_hash.py | 4 ++-- Lib/test/test_os/test_os.py | 4 ++-- Lib/test/test_script_helper.py | 2 +- Lib/test/test_utf8_mode.py | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 8646cfcad58cea..15cce2b30da576 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -1108,7 +1108,8 @@ def run_cli_ok(self, *args): return stdout.buffer.read() def run_cmd_ok(self, *args): - return assert_python_ok('-m', 'calendar', *args)[1] + proc = assert_python_ok('-m', 'calendar', *args) + return proc.out def assertCLIFails(self, *args): with self.captured_stderr_with_buffer() as stderr: diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py index cf9db66a29ae11..63b745f7a9f52f 100644 --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -182,10 +182,10 @@ def get_hash(self, repr_, seed=None): env['PYTHONHASHSEED'] = str(seed) else: env.pop('PYTHONHASHSEED', None) - out = assert_python_ok( + proc = assert_python_ok( '-c', self.get_hash_command(repr_), **env) - stdout = out[1].strip() + stdout = proc.out.strip() return int(stdout) def test_randomized_hash(self): diff --git a/Lib/test/test_os/test_os.py b/Lib/test/test_os/test_os.py index 328a0dbeb99f8f..bcf83a314f1a6e 100644 --- a/Lib/test/test_os/test_os.py +++ b/Lib/test/test_os/test_os.py @@ -2459,8 +2459,8 @@ def get_urandom_subprocess(self, count): 'data = os.urandom(%s)' % count, 'sys.stdout.buffer.write(data)', 'sys.stdout.buffer.flush()')) - out = assert_python_ok('-c', code) - stdout = out[1] + proc = assert_python_ok('-c', code) + stdout = proc.out self.assertEqual(len(stdout), count) return stdout diff --git a/Lib/test/test_script_helper.py b/Lib/test/test_script_helper.py index eeea6c4842b488..e65b3efdcd0a70 100644 --- a/Lib/test/test_script_helper.py +++ b/Lib/test/test_script_helper.py @@ -12,7 +12,7 @@ class TestScriptHelper(unittest.TestCase): def test_assert_python_ok(self): t = script_helper.assert_python_ok('-c', 'import sys; sys.exit(0)') - self.assertEqual(0, t[0], 'return code was not 0') + self.assertEqual(0, t.rc, 'return code was not 0') def test_assert_python_failure(self): # I didn't import the sys module so this child will fail. diff --git a/Lib/test/test_utf8_mode.py b/Lib/test/test_utf8_mode.py index b8e49440c9f7da..6cd156b7e9293a 100644 --- a/Lib/test/test_utf8_mode.py +++ b/Lib/test/test_utf8_mode.py @@ -29,11 +29,11 @@ def posix_locale(self): def get_output(self, *args, failure=False, **kw): kw = dict(self.DEFAULT_ENV, **kw) if failure: - out = assert_python_failure(*args, **kw) - out = out[2] + proc = assert_python_failure(*args, **kw) + out = proc.err else: - out = assert_python_ok(*args, **kw) - out = out[1] + proc = assert_python_ok(*args, **kw) + out = proc.out return out.decode().rstrip("\n\r") @unittest.skipIf(MS_WINDOWS, 'Windows has no POSIX locale')