diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-05 13:28:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-05 13:28:40 (GMT) |
commit | f7b5d419bf871d9cc898982c7b6b4c043f7d5e9d (patch) | |
tree | 9ae7a61c6f1a918db6e7252f32c88be7b08e6273 /Lib | |
parent | 85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20 (diff) | |
download | cpython-f7b5d419bf871d9cc898982c7b6b4c043f7d5e9d.zip cpython-f7b5d419bf871d9cc898982c7b6b4c043f7d5e9d.tar.gz cpython-f7b5d419bf871d9cc898982c7b6b4c043f7d5e9d.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_subprocess.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 2bbdbae..1cebf6b 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1791,7 +1791,12 @@ class POSIXProcessTestCase(BaseTestCase): 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 @@ -1819,7 +1824,7 @@ class POSIXProcessTestCase(BaseTestCase): 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) |