Skip to content

Commit e8a255a

Browse files
author
Charles-François Natali
committed
Issue python#14698: Make test_posix more robust when the current UID doesn't have an
associated pwd entry.
1 parent cb17204 commit e8a255a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎Lib/test/test_posix.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def test_initgroups(self):
107107
# If a non-privileged user invokes it, it should fail with OSError
108108
# EPERM.
109109
if os.getuid() != 0:
110-
name = pwd.getpwuid(posix.getuid()).pw_name
110+
try:
111+
name = pwd.getpwuid(posix.getuid()).pw_name
112+
except KeyError:
113+
# the current UID may not have a pwd entry
114+
raise unittest.SkipTest("need a pwd entry")
111115
try:
112116
posix.initgroups(name, 13)
113117
except OSError as e:
@@ -421,8 +425,9 @@ def _create_and_do_getcwd(dirname, current_path_length = 0):
421425
def test_getgroups(self):
422426
with os.popen('id -G') as idg:
423427
groups = idg.read().strip()
428+
ret = idg.close()
424429

425-
if not groups:
430+
if ret != 0 or not groups:
426431
raise unittest.SkipTest("need working 'id -G'")
427432

428433
# 'id -G' and 'os.getgroups()' should return the same

0 commit comments

Comments
 (0)