summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-24 10:26:25 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-24 10:26:25 (GMT)
commit5e193ac0bd6bd4d4a122fd9aa2446ee70e5f2bf1 (patch)
tree32b9c686d3e209c51c3d3a0fc812e7a6ebc8ddd1 /Lib/test
parentb87630c273ab3ff68d4dbee61fe7ec9c65eeccb8 (diff)
downloadcpython-5e193ac0bd6bd4d4a122fd9aa2446ee70e5f2bf1.zip
cpython-5e193ac0bd6bd4d4a122fd9aa2446ee70e5f2bf1.tar.gz
cpython-5e193ac0bd6bd4d4a122fd9aa2446ee70e5f2bf1.tar.bz2
Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_tempfile.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index ec975f8..2e10fdd 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -1211,6 +1211,30 @@ class TestTemporaryDirectory(BaseTestCase):
self.assertNotIn("Exception ", err)
self.assertIn("ResourceWarning: Implicitly cleaning up", err)
+ def test_exit_on_shutdown(self):
+ # Issue #22427
+ with self.do_create() as dir:
+ code = """if True:
+ import sys
+ import tempfile
+ import warnings
+
+ def generator():
+ with tempfile.TemporaryDirectory(dir={dir!r}) as tmp:
+ yield tmp
+ g = generator()
+ sys.stdout.buffer.write(next(g).encode())
+
+ warnings.filterwarnings("always", category=ResourceWarning)
+ """.format(dir=dir)
+ rc, out, err = script_helper.assert_python_ok("-c", code)
+ tmp_name = out.decode().strip()
+ self.assertFalse(os.path.exists(tmp_name),
+ "TemporaryDirectory %s exists after cleanup" % tmp_name)
+ err = err.decode('utf-8', 'backslashreplace')
+ self.assertNotIn("Exception ", err)
+ self.assertIn("ResourceWarning: Implicitly cleaning up", err)
+
def test_warnings_on_cleanup(self):
# ResourceWarning will be triggered by __del__
with self.do_create() as dir: