Commit 4c26abd1 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

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.
parent 06a8916c
...@@ -124,7 +124,7 @@ def supports_file2file_sendfile(): ...@@ -124,7 +124,7 @@ def supports_file2file_sendfile():
with open(srcname, "rb") as src: with open(srcname, "rb") as src:
with tempfile.NamedTemporaryFile("wb", delete=False) as dst: with tempfile.NamedTemporaryFile("wb", delete=False) as dst:
dstname = f.name dstname = dst.name
infd = src.fileno() infd = src.fileno()
outfd = dst.fileno() outfd = dst.fileno()
try: try:
...@@ -878,8 +878,9 @@ class TestShutil(unittest.TestCase): ...@@ -878,8 +878,9 @@ class TestShutil(unittest.TestCase):
flag = [] flag = []
src = tempfile.mkdtemp() src = tempfile.mkdtemp()
self.addCleanup(support.rmtree, src)
dst = tempfile.mktemp() dst = tempfile.mktemp()
self.addCleanup(shutil.rmtree, src) self.addCleanup(support.rmtree, dst)
with open(os.path.join(src, 'foo'), 'w') as f: with open(os.path.join(src, 'foo'), 'w') as f:
f.close() f.close()
shutil.copytree(src, dst, copy_function=custom_cpfun) shutil.copytree(src, dst, copy_function=custom_cpfun)
......
Fix test_shutil to no longer leak temporary files.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment