From: Charles-François Natali Date: Wed, 2 May 2012 18:01:38 +0000 (+0200) Subject: Issue #14698: Make test_posix more robust when the current UID doesn't have an X-Git-Tag: v3.3.0a4~313^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e8a255a5a28f3d0cecf2bcd411ac959937cde40d;p=thirdparty%2FPython%2Fcpython.git Issue #14698: Make test_posix more robust when the current UID doesn't have an associated pwd entry. --- diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 76126342085f..26b8d81a6436 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -107,7 +107,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: @@ -421,8 +425,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