]> granicus.if.org Git - python/commitdiff
bpo-37421: test_winconsoleio doesn't leak temp file anymore (GH-14562)
authorVictor Stinner <vstinner@redhat.com>
Wed, 3 Jul 2019 09:09:56 +0000 (11:09 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2019 09:09:56 +0000 (11:09 +0200)
test_winconsoleio doesn't leak a temporary file anymore: use
tempfile.TemporaryFile() to remove it when the test completes.

Lib/test/test_winconsoleio.py
Misc/NEWS.d/next/Tests/2019-07-02-23-20-35.bpo-37421.HCkKWz.rst [new file with mode: 0644]

index a78fa4d7d919fffb8846651523120b9956c74f56..9a61e48881d903ca0cf98bad049cc86b9c86674b 100644 (file)
@@ -25,14 +25,12 @@ class WindowsConsoleIOTests(unittest.TestCase):
         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 (file)
index 0000000..6671ffe
--- /dev/null
@@ -0,0 +1,2 @@
+test_winconsoleio doesn't leak a temporary file anymore: use
+tempfile.TemporaryFile() to remove it when the test completes.