[Python-checkins] cpython (3.1): Fix the @test_NNNN_tmp file terds being left in whatever your $PWD was

gregory.p.smith python-checkins at python.org
Tue Mar 15 07:18:32 CET 2011


http://hg.python.org/cpython/rev/141bbcb19c06
changeset:   68491:141bbcb19c06
branch:      3.1
parent:      68488:0991b40e895d
user:        Gregory P. Smith <greg at krypto.org>
date:        Tue Mar 15 02:04:11 2011 -0400
summary:
  Fix the @test_NNNN_tmp file terds being left in whatever your $PWD was
when test_subprocess was run.

files:
  Lib/test/test_subprocess.py

diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -8,6 +8,7 @@
 import tempfile
 import time
 import re
+import shutil
 
 mswindows = (sys.platform == "win32")
 
@@ -450,11 +451,12 @@
         else:
             max_handles = 2050 # too much for (at least some) Windows setups
         handles = []
+        tmpdir = tempfile.mkdtemp()
         try:
             for i in range(max_handles):
                 try:
-                    handles.append(os.open(support.TESTFN,
-                                           os.O_WRONLY | os.O_CREAT))
+                    tmpfile = os.path.join(tmpdir, support.TESTFN)
+                    handles.append(os.open(tmpfile, os.O_WRONLY|os.O_CREAT))
                 except OSError as e:
                     if e.errno != errno.EMFILE:
                         raise
@@ -479,6 +481,7 @@
         finally:
             for h in handles:
                 os.close(h)
+            shutil.rmtree(tmpdir)
 
     def test_list2cmdline(self):
         self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list