diff -r 63c5531cfdf7 Lib/test/support/__init__.py --- a/Lib/test/support/__init__.py Sat Jan 07 09:33:28 2017 +0300 +++ b/Lib/test/support/__init__.py Sat Jan 07 21:40:05 2017 +0100 @@ -107,7 +107,7 @@ "check_warnings", "check_no_resource_warning", "EnvironmentVarGuard", "run_with_locale", "swap_item", "swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict", - "run_with_tz", "PGO", "missing_compiler_executable", + "run_with_tz", "PGO", "missing_compiler_executable", "os_link", ] class Error(Exception): @@ -2573,6 +2573,14 @@ return cmd[0] +def os_link(src, dst, **kwds): + """Create a hard link, raising SkipTest if PermissionError is raised.""" + try: + os.link(src, dst, **kwds) + except PermissionError: + raise unittest.SkipTest('cannot create a hard link') + + _is_android_emulator = None def setswitchinterval(interval): # Setting a very low gil interval on the Android emulator causes python diff -r 63c5531cfdf7 Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py Sat Jan 07 09:33:28 2017 +0300 +++ b/Lib/test/test_tarfile.py Sat Jan 07 21:40:05 2017 +0100 @@ -1099,7 +1099,7 @@ target = os.path.join(TEMPDIR, "link_target") with open(target, "wb") as fobj: fobj.write(b"aaa") - os.link(target, link) + support.os_link(target, link) try: tar = tarfile.open(tmpname, self.mode) try: @@ -1560,7 +1560,7 @@ with open(self.foo, "wb") as fobj: fobj.write(b"foo") - os.link(self.foo, self.bar) + support.os_link(self.foo, self.bar) self.tar = tarfile.open(tmpname, "w") self.tar.add(self.foo)