diff -r 99a436de7029 Lib/shutil.py --- a/Lib/shutil.py Thu Sep 06 18:58:43 2012 +0200 +++ b/Lib/shutil.py Fri Sep 07 01:03:28 2012 +0100 @@ -452,8 +452,9 @@ except os.error: onerror(os.rmdir, path, sys.exc_info()) else: - raise NotADirectoryError(20, - "Not a directory: '{}'".format(path)) + if not ignore_errors: + raise NotADirectoryError(20, + "Not a directory: '{}'".format(path)) finally: os.close(fd) else: diff -r 99a436de7029 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Thu Sep 06 18:58:43 2012 +0200 +++ b/Lib/test/test_shutil.py Fri Sep 07 01:03:28 2012 +0100 @@ -153,6 +153,12 @@ # filename is guaranteed not to exist filename = tempfile.mktemp() self.assertRaises(OSError, shutil.rmtree, filename) + # test that ignore_errors option is honoured + tmpdir = self.mkdtemp() + write_file((tmpdir, "tstfile"), "") + self.assertEqual(shutil.rmtree(os.path.join(tmpdir, "tstfile"), + ignore_errors=True), None) + # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root.