8000 bpo-37421: Fix test_shutil: don't leak temporary files (GH-14416) · python/cpython@7fe81ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fe81ce

Browse files
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 4c26abd) Co-authored-by: Victor Stinner <vstinner@redhat.com>
1 parent 82654a0 commit 7fe81ce

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/test/test_shutil.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def supports_file2file_sendfile():
124124

125125
with open(srcname, "rb") as src:
126126
with tempfile.NamedTemporaryFile("wb", delete=False) as dst:
127-
dstname = f.name
127+
dstname = dst.name
128128
infd = src.fileno()
129129
outfd = dst.fileno()
130130
try:
@@ -878,8 +878,9 @@ def custom_cpfun(a, b):
878878

879879
flag = []
880880
src = tempfile.mkdtemp()
881+
self.addCleanup(support.rmtree, src)
881882
dst = tempfile.mktemp()
882-
self.addCleanup(shutil.rmtree, src)
883+
self.addCleanup(support.rmtree, dst)
883884
with open(os.path.join(src, 'foo'), 'w') as f:
884885
f.close()
885886
shutil.copytree(src, dst, copy_function=custom_cpfun)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix test_shutil to no longer leak temporary files.

0 commit comments

Comments
 (0)
0