]> granicus.if.org Git - python/commitdiff
bpo-37421: Fix test_shutil: don't leak temporary files (GH-14416)
authorVictor Stinner <vstinner@redhat.com>
Wed, 26 Jun 2019 23:39:53 +0000 (01:39 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Jun 2019 23:39:53 +0000 (01:39 +0200)
* Fix typo in supports_file2file_sendfile(); ensure that dst is
  removed
* Fix test_copytree_custom_copy_function(): remove dst tree.
  Use support.rmtree() rather than shutil.rmtree() to remove
  temporary directories: support tries harder.

Lib/test/test_shutil.py
Misc/NEWS.d/next/Tests/2019-06-27-00-37-59.bpo-37421.rVJb3x.rst [new file with mode: 0644]

index 208718bb1281050c0570a9c024cc156a46291f0f..e209607f22c1458fb67a644ff6574efa682fcb12 100644 (file)
@@ -124,7 +124,7 @@ def supports_file2file_sendfile():
 
         with open(srcname, "rb") as src:
             with tempfile.NamedTemporaryFile("wb", delete=False) as dst:
-                dstname = f.name
+                dstname = dst.name
                 infd = src.fileno()
                 outfd = dst.fileno()
                 try:
@@ -878,8 +878,9 @@ class TestShutil(unittest.TestCase):
 
         flag = []
         src = tempfile.mkdtemp()
+        self.addCleanup(support.rmtree, src)
         dst = tempfile.mktemp()
-        self.addCleanup(shutil.rmtree, src)
+        self.addCleanup(support.rmtree, dst)
         with open(os.path.join(src, 'foo'), 'w') as f:
             f.close()
         shutil.copytree(src, dst, copy_function=custom_cpfun)
diff --git a/Misc/NEWS.d/next/Tests/2019-06-27-00-37-59.bpo-37421.rVJb3x.rst b/Misc/NEWS.d/next/Tests/2019-06-27-00-37-59.bpo-37421.rVJb3x.rst
new file mode 100644 (file)
index 0000000..9f40338
--- /dev/null
@@ -0,0 +1 @@
+Fix test_shutil to no longer leak temporary files.