Anonymous committed 45f0272

Issue #14698: Make test_posix more robust when the current UID doesn't have an
associated pwd entry.

Comments (0)

Files changed (1)


         # 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")
                 posix.initgroups(name, 13)
             except OSError as e:
     def test_getgroups(self):
         with os.popen('id -G') as idg:
             groups =
+            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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.