Skip to content

Commit

Permalink
pythongh-104522: Fix test_subprocess failure when build Python in the…
Browse files Browse the repository at this point in the history
… root home directory (pythonGH-114236)

* pythongh-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>
  • Loading branch information
serhiy-storchaka authored and miss-islington committed Jan 18, 2024
1 parent 2c98724 commit 5748b0a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Lib/test/test_subprocess.py
Expand Up @@ -2004,9 +2004,9 @@ def test_process_group_0(self):

@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]
Expand All @@ -2031,11 +2031,10 @@ def test_user(self):
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
Expand Down

0 comments on commit 5748b0a

Please sign in to comment.