]> granicus.if.org Git - python/commitdiff
bpo-30693: Fix tarfile test cleanup on MSWindows (#5557)
authorBernhard M. Wiedemann <githubbmw@lsmod.de>
Tue, 6 Feb 2018 18:08:53 +0000 (19:08 +0100)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 6 Feb 2018 18:08:53 +0000 (20:08 +0200)
it was using our mocked listdir to check when the files were gone.

Lib/test/test_tarfile.py

index 8ef4294921b24924aee5c5999856e6818fc4e1f0..b868326d5c74a1f34fcc2086dc6a1fbf70fba66e 100644 (file)
@@ -1131,17 +1131,17 @@ class WriteTest(WriteTestBase, unittest.TestCase):
 
     # mock the following:
     #  os.listdir: so we know that files are in the wrong order
-    @unittest.mock.patch('os.listdir')
-    def test_ordered_recursion(self, mock_listdir):
+    def test_ordered_recursion(self):
         path = os.path.join(TEMPDIR, "directory")
         os.mkdir(path)
         open(os.path.join(path, "1"), "a").close()
         open(os.path.join(path, "2"), "a").close()
-        mock_listdir.return_value = ["2", "1"]
         try:
             tar = tarfile.open(tmpname, self.mode)
             try:
-                tar.add(path)
+                with unittest.mock.patch('os.listdir') as mock_listdir:
+                    mock_listdir.return_value = ["2", "1"]
+                    tar.add(path)
                 paths = []
                 for m in tar.getmembers():
                     paths.append(os.path.split(m.name)[-1])