Skip to content

bpo-39855: Fix test_subprocess if nobody user doesn't exist (GH-18781) #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,12 @@ def test_user(self):
name_uid = "nobody" if sys.platform != 'darwin' else "unknown"

if pwd is not None:
test_users.append(name_uid)
try:
pwd.getpwnam(name_uid)
test_users.append(name_uid)
except KeyError:
# unknown user name
name_uid = None

for user in test_users:
# posix_spawn() may be used with close_fds=False
Expand Down Expand Up @@ -1819,7 +1824,7 @@ def test_user(self):
with self.assertRaises(ValueError):
subprocess.check_call(ZERO_RETURN_CMD, user=-1)

if pwd is None:
if pwd is None and name_uid is not None:
with self.assertRaises(ValueError):
subprocess.check_call(ZERO_RETURN_CMD, user=name_uid)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_subprocess.test_user() now skips the test on an user name if the user
name doesn't exist. For example, skip the test if the user "nobody" doesn't
exist on Linux.