]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-104522: Fix test_subprocess failure when build Python in the root home...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 18 Jan 2024 12:19:18 +0000 (13:19 +0100)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2024 12:19:18 +0000 (13:19 +0100)
EPERM is raised when setreuid() fails.
EACCES is set in execve() when the test user has not access to sys.executable.
(cherry picked from commit 311d1e2701037952eaf75f993be76f3092c1f01c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_subprocess.py

index b4206c7bea897de69696cf81a9012202f8b548d0..7f7d84214b0e860fedd5fbe7b353ba7f491d7e8a 100644 (file)
@@ -2004,9 +2004,9 @@ class POSIXProcessTestCase(BaseTestCase):
 
     @unittest.skipUnless(hasattr(os, 'setreuid'), 'no setreuid on platform')
     def test_user(self):
-        # For code coverage of the user parameter.  We don't care if we get an
-        # EPERM error from it depending on the test execution environment, that
-        # still indicates that it was called.
+        # For code coverage of the user parameter.  We don't care if we get a
+        # permission error from it depending on the test execution environment,
+        # that still indicates that it was called.
 
         uid = os.geteuid()
         test_users = [65534 if uid != 65534 else 65533, uid]
@@ -2031,11 +2031,10 @@ class POSIXProcessTestCase(BaseTestCase):
                                 user=user,
                                 close_fds=close_fds)
                     except PermissionError as e:  # (EACCES, EPERM)
-                        self.assertIsNone(e.filename)
-                    except OSError as e:
-                        if e.errno not in (errno.EACCES, errno.EPERM):
-                            raise
-                        self.assertIsNone(e.filename)
+                        if e.errno == errno.EACCES:
+                            self.assertEqual(e.filename, sys.executable)
+                        else:
+                            self.assertIsNone(e.filename)
                     else:
                         if isinstance(user, str):
                             user_uid = pwd.getpwnam(user).pw_uid