summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-05-02 18:04:40 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-05-02 18:04:40 (GMT)
commitd59240de8311a493ead948f382cc07e0d70fb1c1 (patch)
tree1dae58dcae0192d6e82a735a6c804a7152e006c4 /Lib
parent67880cc962edb12c3d5cdd063ba9664d18d39aa9 (diff)
parente8a255a5a28f3d0cecf2bcd411ac959937cde40d (diff)
downloadcpython-d59240de8311a493ead948f382cc07e0d70fb1c1.zip
cpython-d59240de8311a493ead948f382cc07e0d70fb1c1.tar.gz
cpython-d59240de8311a493ead948f382cc07e0d70fb1c1.tar.bz2
Issue #14698: Make test_posix more robust when the current UID doesn't have an
associated pwd entry.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_posix.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 142dddd..5ed2a0f 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -108,7 +108,11 @@ class PosixTester(unittest.TestCase):
# If a non-privileged user invokes it, it should fail with OSError
# EPERM.
if os.getuid() != 0:
- name = pwd.getpwuid(posix.getuid()).pw_name
+ try:
+ name = pwd.getpwuid(posix.getuid()).pw_name
+ except KeyError:
+ # the current UID may not have a pwd entry
+ raise unittest.SkipTest("need a pwd entry")
try:
posix.initgroups(name, 13)
except OSError as e:
@@ -624,8 +628,9 @@ class PosixTester(unittest.TestCase):
def test_getgrouplist(self):
with os.popen('id -G') as idg:
groups = idg.read().strip()
+ ret = idg.close()
- if not groups:
+ if ret != 0 or not groups:
raise unittest.SkipTest("need working 'id -G'")
self.assertEqual(
@@ -637,8 +642,9 @@ class PosixTester(unittest.TestCase):
def test_getgroups(self):
with os.popen('id -G') as idg:
groups = idg.read().strip()
+ ret = idg.close()
- if not groups:
+ if ret != 0 or not groups:
raise unittest.SkipTest("need working 'id -G'")
# 'id -G' and 'os.getgroups()' should return the same