diff -r a0f67eb0233f Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Fri Jun 06 16:48:40 2008 +0200 +++ b/Lib/test/test_shutil.py Fri Jun 06 16:54:14 2008 +0200 @@ -32,22 +32,27 @@ os.chmod(self.childpath, stat.S_IREAD) os.chmod(TESTFN, stat.S_IREAD) - shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror) - # Test whether onerror has actually been called. - self.assertEqual(self.errorState, 2, - "Expected call to onerror function did not happen.") + try: + shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror) + # Test whether onerror has actually been called. + self.assertEqual(self.errorState, 2, + "Expected call to onerror function did not happen.") - # Make writable again. - os.chmod(TESTFN, old_dir_mode) - os.chmod(self.childpath, old_child_mode) + finally: + # Make writable again. + os.chmod(TESTFN, old_dir_mode) + os.chmod(self.childpath, old_child_mode) - # Clean up. - shutil.rmtree(TESTFN) + # Clean up. + shutil.rmtree(TESTFN) def check_args_to_onerror(self, func, arg, exc): if self.errorState == 0: - self.assertEqual(func, os.remove) - self.assertEqual(arg, self.childpath) + # See #3053 for why the failing function can sometimes + # be os.listdir. + self.assertTrue(func in (os.remove, os.listdir), func) + if func is os.remove: + self.assertEqual(arg, self.childpath) self.failUnless(issubclass(exc[0], OSError)) self.errorState = 1 else: