gh-155358: Use named attributes with test.support.script_helper (#155367)

vstinner <[email protected]> Mon, 10 Aug 2026 14:28:59 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/38235c0e8034467b9589748161d9f8ebe74d6471
commit: 38235c0e8034467b9589748161d9f8ebe74d6471
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-08-10T20:28:46+02:00
summary:

gh-155358: Use named attributes with test.support.script_helper (#155367)

Replace assert_python_ok() result:

* proc[0] => proc.rc
* proc[1] => proc.out
* proc[2] => proc.err

files:
M Lib/test/test_calendar.py
M Lib/test/test_hash.py
M Lib/test/test_os/test_os.py
M Lib/test/test_script_helper.py
M Lib/test/test_utf8_mode.py

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')

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]