Issue #26385: Cleanup NamedTemporaryFile if fdopen() fails, by SilentGhost
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 3d0ac57..078e4a9 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -827,6 +827,13 @@
             os.close = old_close
             os.fdopen = old_fdopen
 
+    def test_bad_mode(self):
+        dir = tempfile.mkdtemp()
+        self.addCleanup(support.rmtree, dir)
+        with self.assertRaises(TypeError):
+            tempfile.NamedTemporaryFile(mode=(), dir=dir)
+        self.assertEqual(os.listdir(dir), [])
+
     # How to test the mode and bufsize parameters?
 
 test_classes.append(test_NamedTemporaryFile)