diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -16,6 +16,7 @@ import stat import tempfile import unittest import warnings +import platform _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(), support.TESTFN + '-dummy-symlink') @@ -387,6 +388,9 @@ class PosixTester(unittest.TestCase): def _test_all_chown_common(self, chown_func, first_param): """Common code for chown, fchown and lchown tests.""" + # test a successful chown call + chown_func(first_param, os.getuid(), os.getgid()) + if os.getuid() == 0: try: # Many linux distros have a nfsnobody user as MAX_UID-2 @@ -398,12 +402,12 @@ class PosixTester(unittest.TestCase): chown_func(first_param, ent.pw_uid, ent.pw_gid) except KeyError: pass - else: + # HP-UX and Solaris allow a non-root user to chown to root (issue + # #5113) + elif platform.system() not in ('HP-UX', 'SunOS'): # non-root cannot chown to root, raises OSError self.assertRaises(OSError, chown_func, first_param, 0, 0) - # test a successful chown call - chown_func(first_param, os.getuid(), os.getgid()) @unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()") def test_chown(self):