]> granicus.if.org Git - python/commitdiff
Issue #14698: Make test_posix more robust when the current UID doesn't have an
authorCharles-François Natali <neologix@free.fr>
Wed, 2 May 2012 18:00:37 +0000 (20:00 +0200)
committerCharles-François Natali <neologix@free.fr>
Wed, 2 May 2012 18:00:37 +0000 (20:00 +0200)
associated pwd entry.

Lib/test/test_posix.py

index 684326a44de58c9eab629b749afcc65463599403..06f3fdd9920ada94fafa934e7506c08b206e0a16 100644 (file)
@@ -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