[Python-checkins] bpo-37421: test_winconsoleio doesn't leak temp file anymore (GH-14562)

Miss Islington (bot) webhook-mailer at python.org
Wed Jul 3 05:31:44 EDT 2019


https://github.com/python/cpython/commit/a2a807f75dc162dfb45fb297aee4961de8008f84
commit: a2a807f75dc162dfb45fb297aee4961de8008f84
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-07-03T02:31:39-07:00
summary:

bpo-37421: test_winconsoleio doesn't leak temp file anymore (GH-14562)


test_winconsoleio doesn't leak a temporary file anymore: use
tempfile.TemporaryFile() to remove it when the test completes.
(cherry picked from commit b71d8d67959f3b5efbdfe00066589ac0d8f98aad)

Co-authored-by: Victor Stinner <vstinner at redhat.com>

files:
A Misc/NEWS.d/next/Tests/2019-07-02-23-20-35.bpo-37421.HCkKWz.rst
M Lib/test/test_winconsoleio.py

diff --git a/Lib/test/test_winconsoleio.py b/Lib/test/test_winconsoleio.py
index a78fa4d7d919..9a61e48881d9 100644
--- a/Lib/test/test_winconsoleio.py
+++ b/Lib/test/test_winconsoleio.py
@@ -25,14 +25,12 @@ def test_open_fd(self):
         self.assertRaisesRegex(ValueError,
             "negative file descriptor", ConIO, -1)
 
-        fd, _ = tempfile.mkstemp()
-        try:
+        with tempfile.TemporaryFile() as tmpfile:
+            fd = tmpfile.fileno()
             # Windows 10: "Cannot open non-console file"
             # Earlier: "Cannot open console output buffer for reading"
             self.assertRaisesRegex(ValueError,
                 "Cannot open (console|non-console file)", ConIO, fd)
-        finally:
-            os.close(fd)
 
         try:
             f = ConIO(0)
diff --git a/Misc/NEWS.d/next/Tests/2019-07-02-23-20-35.bpo-37421.HCkKWz.rst b/Misc/NEWS.d/next/Tests/2019-07-02-23-20-35.bpo-37421.HCkKWz.rst
new file mode 100644
index 000000000000..6671ffe922fd
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-07-02-23-20-35.bpo-37421.HCkKWz.rst
@@ -0,0 +1,2 @@
+test_winconsoleio doesn't leak a temporary file anymore: use
+tempfile.TemporaryFile() to remove it when the test completes.



More information about the Python-checkins mailing list