From: Victor Stinner Date: Thu, 24 Mar 2016 16:21:17 +0000 (+0100) Subject: test_os: use support.rmtree() to cleanup WalkTests X-Git-Tag: v3.6.0a1~351 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3899b549e3d1acb1f0f7bc5d226cc3632675d36d;p=python test_os: use support.rmtree() to cleanup WalkTests --- diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 17484fe549..bc24e47c9c 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -812,6 +812,7 @@ class WalkTests(unittest.TestCase): def setUp(self): join = os.path.join + self.addCleanup(support.rmtree, support.TESTFN) # Build: # TESTFN/ @@ -922,22 +923,6 @@ class WalkTests(unittest.TestCase): else: self.fail("Didn't follow symlink with followlinks=True") - def tearDown(self): - # Tear everything down. This is a decent use for bottom-up on - # Windows, which doesn't have a recursive delete command. The - # (not so) subtlety is that rmdir will fail unless the dir's - # kids are removed first, so bottom up is essential. - for root, dirs, files in os.walk(support.TESTFN, topdown=False): - for name in files: - os.remove(os.path.join(root, name)) - for name in dirs: - dirname = os.path.join(root, name) - if not os.path.islink(dirname): - os.rmdir(dirname) - else: - os.remove(dirname) - os.rmdir(support.TESTFN) - def test_walk_bad_dir(self): # Walk top-down. errors = [] @@ -1020,19 +1005,6 @@ class FwalkTests(WalkTests): self.addCleanup(os.close, newfd) self.assertEqual(newfd, minfd) - def tearDown(self): - # cleanup - for root, dirs, files, rootfd in os.fwalk(support.TESTFN, topdown=False): - for name in files: - os.unlink(name, dir_fd=rootfd) - for name in dirs: - st = os.stat(name, dir_fd=rootfd, follow_symlinks=False) - if stat.S_ISDIR(st.st_mode): - os.rmdir(name, dir_fd=rootfd) - else: - os.unlink(name, dir_fd=rootfd) - os.rmdir(support.TESTFN) - class BytesWalkTests(WalkTests): """Tests for os.walk() with bytes.""" def setUp(self):