[Python-checkins] bpo-39855: Fix test_subprocess if nobody user doesn't exist (GH-18781)
Victor Stinner
webhook-mailer at python.org
Thu Mar 5 08:29:03 EST 2020
https://github.com/python/cpython/commit/f7b5d419bf871d9cc898982c7b6b4c043f7d5e9d
commit: f7b5d419bf871d9cc898982c7b6b4c043f7d5e9d
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-03-05T14:28:40+01:00
summary:
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.
files:
A Misc/NEWS.d/next/Tests/2020-03-04-23-03-01.bpo-39855.Ql5xv8.rst
M Lib/test/test_subprocess.py
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 2bbdbaef84e99..1cebf6b24a69e 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -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
@@ -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)
diff --git a/Misc/NEWS.d/next/Tests/2020-03-04-23-03-01.bpo-39855.Ql5xv8.rst b/Misc/NEWS.d/next/Tests/2020-03-04-23-03-01.bpo-39855.Ql5xv8.rst
new file mode 100644
index 0000000000000..060124129042d
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-03-04-23-03-01.bpo-39855.Ql5xv8.rst
@@ -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.
More information about the Python-checkins
mailing list