diff -r 1266e98fd04c Lib/test/test_compileall.py --- a/Lib/test/test_compileall.py Fri Sep 25 13:05:13 2015 -0700 +++ b/Lib/test/test_compileall.py Fri Sep 25 13:52:24 2015 -0700 @@ -165,6 +165,22 @@ sys.stdout = orig_stdout +for path in filter(os.path.isdir, sys.path): + try: + path = os.path.join(path, '__pycache__', 'test.pyc') + if not os.path.isdir(os.path.dirname(path)): + continue + with open(path, 'w') as file: + file.write('# for test_compileall') + except OSError: + sys_path_writable = False + break + else: + os.unlink(path) +else: + sys_path_writable = True + + class CommandLineTests(unittest.TestCase): """Test compileall's CLI.""" @@ -194,8 +210,8 @@ self.assertFalse(os.path.exists(path)) def setUp(self): - self.addCleanup(self._cleanup) self.directory = tempfile.mkdtemp() + self.addCleanup(support.rmtree, self.directory) self.pkgdir = os.path.join(self.directory, 'foo') os.mkdir(self.pkgdir) self.pkgdir_cachedir = os.path.join(self.pkgdir, '__pycache__') @@ -203,9 +219,8 @@ self.initfn = script_helper.make_script(self.pkgdir, '__init__', '') self.barfn = script_helper.make_script(self.pkgdir, 'bar', '') - def _cleanup(self): - support.rmtree(self.directory) - + @unittest.skipUnless(sys_path_writable, + 'not all entries on sys.path are writable') def test_no_args_compiles_path(self): # Note that -l is implied for the no args case. bazfn = script_helper.make_script(self.directory, 'baz', '') @@ -214,6 +229,8 @@ self.assertNotCompiled(self.initfn) self.assertNotCompiled(self.barfn) + @unittest.skipUnless(sys_path_writable, + 'not all entries on sys.path are writable') def test_no_args_respects_force_flag(self): bazfn = script_helper.make_script(self.directory, 'baz', '') self.assertRunOK(PYTHONPATH=self.directory) @@ -230,6 +247,8 @@ mtime2 = os.stat(pycpath).st_mtime self.assertNotEqual(mtime, mtime2) + @unittest.skipUnless(sys_path_writable, + 'not all entries on sys.path are writable') def test_no_args_respects_quiet_flag(self): script_helper.make_script(self.directory, 'baz', '') noisy = self.assertRunOK(PYTHONPATH=self.directory)