Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ def collect_pwd(info_add):
return

if hasattr(os, 'getgrouplist'):
groups = os.getgrouplist(entry.pw_name, entry.pw_gid)
groups = ', '.join(map(str, groups))
info_add('os.getgrouplist', groups)
try:
groups = os.getgrouplist(entry.pw_name, entry.pw_gid)
groups = ', '.join(map(str, groups))
except OSError:
pass
else:
info_add('os.getgrouplist', groups)


def collect_readline(info_add):
Expand Down
11 changes: 9 additions & 2 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,15 @@ def _create_and_do_getcwd(dirname, current_path_length = 0):
def test_getgrouplist(self):
user = pwd.getpwuid(os.getuid())[0]
group = pwd.getpwuid(os.getuid())[3]
self.assertIn(group, posix.getgrouplist(user, group))

try:
self.assertIn(group, posix.getgrouplist(user, group))
except OSError as e:
# bpo-40014: getgrouplist fails with
# "[Errno 25] Inappropriate ioctl for device" on macOS
if sys.platform == 'darwin':
raise unittest.SkipTest("bpo-40014: os.getgrouplist() is not available")
else:
raise e

@unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()")
def test_getgroups(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test.pythoninfo: skip :func:`~os.getgrouplist` if it raises an :exc:`OSError`.
Patch by Dong-hee Na.