Skip to content

Commit 907676b

Browse files
committed
gh-152936: Fix test_os and test_posix failures on Android
1 parent 27e854c commit 907676b

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/test/test_os/test_os.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4517,7 +4517,10 @@ def test_oserror_filename(self):
45174517
try:
45184518
func(name, *func_args)
45194519
except OSError as err:
4520-
self.assertIs(err.filename, name, str(func))
4520+
if func is os.chroot and support.is_android and os.getuid() != 0:
4521+
self.assertIsNone(err.filename, str(func))
4522+
else:
4523+
self.assertIs(err.filename, name, str(func))
45214524
except UnicodeDecodeError:
45224525
pass
45234526
else:

Lib/test/test_os/test_posix.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def test_getresgid(self):
9999
@unittest.skipUnless(hasattr(posix, 'setresuid'),
100100
'test needs posix.setresuid()')
101101
def test_setresuid(self):
102+
if support.is_android and os.getuid() != 0:
103+
self.assertRaises(PermissionError, posix.setresuid, -1, -1, -1)
104+
return
102105
current_user_ids = posix.getresuid()
103106
self.assertIsNone(posix.setresuid(*current_user_ids))
104107
# -1 means don't change that value.
@@ -116,6 +119,9 @@ def test_setresuid_exception(self):
116119
@unittest.skipUnless(hasattr(posix, 'setresgid'),
117120
'test needs posix.setresgid()')
118121
def test_setresgid(self):
122+
if support.is_android and os.getuid() != 0:
123+
self.assertRaises(PermissionError, posix.setresgid, -1, -1, -1)
124+
return
119125
current_group_ids = posix.getresgid()
120126
self.assertIsNone(posix.setresgid(*current_group_ids))
121127
# -1 means don't change that value.

0 commit comments

Comments
 (0)