summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_posix.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-05-02 18:00:37 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-05-02 18:00:37 (GMT)
commit666a573fa610afb5cf766d430f4f3bc5e602eed3 (patch)
tree1b73b70c07693d9b95c6d1619af6b0a0da9e3132 /Lib/test/test_posix.py
parent0c200c282b460d84e0f8ddd56ce10cc79dfb3600 (diff)
downloadcpython-666a573fa610afb5cf766d430f4f3bc5e602eed3.zip
cpython-666a573fa610afb5cf766d430f4f3bc5e602eed3.tar.gz
cpython-666a573fa610afb5cf766d430f4f3bc5e602eed3.tar.bz2
Issue #14698: Make test_posix more robust when the current UID doesn't have an
associated pwd entry.
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r--Lib/test/test_posix.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 684326a..06f3fdd 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:
@@ -418,8 +422,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