Skip to content

Commit 363dddb

Browse files
[3.11] gh-104522: Fix test_subprocess failure when build Python in the root home directory (GH-114236) (GH-114245)
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 311d1e2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 2c98724 commit 363dddb

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Lib/test/test_subprocess.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -2004,9 +2004,9 @@ def test_process_group_0(self):
20042004

20052005
@unittest.skipUnless(hasattr(os, 'setreuid'), 'no setreuid on platform')
20062006
def test_user(self):
2007-
# For code coverage of the user parameter. We don't care if we get an
2008-
# EPERM error from it depending on the test execution environment, that
2009-
# still indicates that it was called.
2007+
# For code coverage of the user parameter. We don't care if we get a
2008+
# permission error from it depending on the test execution environment,
2009+
# that still indicates that it was called.
20102010

20112011
uid = os.geteuid()
20122012
test_users = [65534 if uid != 65534 else 65533, uid]
@@ -2031,11 +2031,10 @@ def test_user(self):
20312031
user=user,
20322032
close_fds=close_fds)
20332033
except PermissionError as e: # (EACCES, EPERM)
2034-
self.assertIsNone(e.filename)
2035-
except OSError as e:
2036-
if e.errno not in (errno.EACCES, errno.EPERM):
2037-
raise
2038-
self.assertIsNone(e.filename)
2034+
if e.errno == errno.EACCES:
2035+
self.assertEqual(e.filename, sys.executable)
2036+
else:
2037+
self.assertIsNone(e.filename)
20392038
else:
20402039
if isinstance(user, str):
20412040
user_uid = pwd.getpwnam(user).pw_uid

0 commit comments

Comments
 (0)