Skip to content

Commit 381685d

Browse files
serhiy-storchakamiss-islington
authored andcommitted
gh-104522: Fix test_subprocess failure when build Python in the root home directory (GH-114236)
* gh-104522: Fix test_subprocess failure when build Python in the root home directory 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 55b73a5 commit 381685d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Lib/test/test_subprocess.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,9 +2006,9 @@ def test_process_group_0(self):
20062006

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

20132013
uid = os.geteuid()
20142014
test_users = [65534 if uid != 65534 else 65533, uid]
@@ -2033,11 +2033,10 @@ def test_user(self):
20332033
user=user,
20342034
close_fds=close_fds)
20352035
except PermissionError as e: # (EACCES, EPERM)
2036-
self.assertIsNone(e.filename)
2037-
except OSError as e:
2038-
if e.errno not in (errno.EACCES, errno.EPERM):
2039-
raise
2040-
self.assertIsNone(e.filename)
2036+
if e.errno == errno.EACCES:
2037+
self.assertEqual(e.filename, sys.executable)
2038+
else:
2039+
self.assertIsNone(e.filename)
20412040
else:
20422041
if isinstance(user, str):
20432042
user_uid = pwd.getpwnam(user).pw_uid

0 commit comments

Comments
 (0)