From 2c914321e2d5f38f67da59107eec720cf2a1c648 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 27 Jun 2019 01:39:53 +0200 Subject: [PATCH] bpo-37421: Fix test_shutil: don't leak temporary files (GH-14416) * 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. (cherry picked from commit 4c26abd14f1b7242998eb2f7756aa375e0fe714f) Co-authored-by: Victor Stinner --- Lib/test/test_shutil.py | 5 +++-- .../next/Tests/2019-06-27-00-37-59.bpo-37421.rVJb3x.rst | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2019-06-27-00-37-59.bpo-37421.rVJb3x.rst diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 208718bb128105..e209607f22c145 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -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 @@ def custom_cpfun(a, b): 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 index 00000000000000..9f4033831d68a6 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-06-27-00-37-59.bpo-37421.rVJb3x.rst @@ -0,0 +1 @@ +Fix test_shutil to no longer leak temporary files.