Skip to content

Commit f7b5d41

Browse files
authored
bpo-39855: Fix test_subprocess if nobody user doesn't exist (GH-18781)
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.
1 parent 85cf1d5 commit f7b5d41

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Lib/test/test_subprocess.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,12 @@ def test_user(self):
17911791
name_uid = "nobody" if sys.platform != 'darwin' else "unknown"
17921792

17931793
if pwd is not None:
1794-
test_users.append(name_uid)
1794+
try:
1795+
pwd.getpwnam(name_uid)
1796+
test_users.append(name_uid)
1797+
except KeyError:
1798+
# unknown user name
1799+
name_uid = None
17951800

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

1822-
if pwd is None:
1827+
if pwd is None and name_uid is not None:
18231828
with self.assertRaises(ValueError):
18241829
subprocess.check_call(ZERO_RETURN_CMD, user=name_uid)
18251830

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_subprocess.test_user() now skips the test on an user name if the user
2+
name doesn't exist. For example, skip the test if the user "nobody" doesn't
3+
exist on Linux.

0 commit comments

Comments
 (0)