]> granicus.if.org Git - python/commitdiff
Issue #7367: Ensure test directory always gets removed.
authorNed Deily <nad@acm.org>
Fri, 7 Oct 2011 19:01:40 +0000 (12:01 -0700)
committerNed Deily <nad@acm.org>
Fri, 7 Oct 2011 19:01:40 +0000 (12:01 -0700)
Lib/test/test_pkgutil.py

index f755e674649a78fb72d0c47e60b158b690efa5e1..f4e03234e94911fb3bb379582fc1c0f14d5b9d84 100644 (file)
@@ -15,11 +15,11 @@ class PkgutilTests(unittest.TestCase):
 
     def setUp(self):
         self.dirname = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, self.dirname)
         sys.path.insert(0, self.dirname)
 
     def tearDown(self):
         del sys.path[0]
-        shutil.rmtree(self.dirname)
 
     def test_getdata_filesys(self):
         pkg = 'test_getdata_filesys'
@@ -91,9 +91,9 @@ class PkgutilTests(unittest.TestCase):
         # this does not appear to create an unreadable dir on Windows
         #   but the test should not fail anyway
         os.mkdir(d, 0)
+        self.addCleanup(os.rmdir, d)
         for t in pkgutil.walk_packages(path=[self.dirname]):
             self.fail("unexpected package found")
-        os.rmdir(d)
 
 class PkgutilPEP302Tests(unittest.TestCase):