[Zodb-checkins] CVS: ZODB4 - test.py:1.17

Jeremy Hylton jeremy at zope.com
Tue Jun 24 18:39:28 EDT 2003


Update of /cvs-repository/ZODB4
In directory cvs.zope.org:/tmp/cvs-serv3190

Modified Files:
	test.py 
Log Message:
New hack: -n puts tempfiles in a per-test directory.

If the directory is empty at the end of the test run, it is removed.
If not, the directory name is a clue about the test that left the
files behind.


=== ZODB4/test.py 1.16 => 1.17 ===
--- ZODB4/test.py:1.16	Tue Jun 24 15:33:30 2003
+++ ZODB4/test.py	Tue Jun 24 17:39:28 2003
@@ -78,6 +78,9 @@
     Keep running the selected tests in a loop.  You may experience
     memory leakage.
 
+-n
+    Name temporary files after the test that is running.
+
 -t
     Time the individual tests and print a list of the top 50, sorted from
     longest to shortest.
@@ -150,9 +153,10 @@
 
 import gc
 import os
-import re
 import pdb
+import re
 import sys
+import tempfile
 import time
 import traceback
 import unittest
@@ -196,6 +200,10 @@
 
     def stopTest(self, test):
         self._testtimes[test] = time.time() - self._testtimes[test]
+        if PATCH_TEMPFILE:
+            tempfile.tempdir = self._old_dir
+            if not os.listdir(self._new_dir):
+                os.rmdir(self._new_dir)
         if gc.garbage:
             print "The following test left garbage:"
             print test
@@ -244,6 +252,15 @@
                 self.stream.write(": %s" % name)
                 self._lastWidth = width
             self.stream.flush()
+        if PATCH_TEMPFILE:
+            # It sure is dumb that unittest hides the test's name.
+            name = test._TestCase__testMethodName
+            self._old_dir = tempfile.gettempdir()
+            self._new_dir = os.path.join(self._old_dir, name)
+            if not os.path.exists(self._new_dir):
+                os.mkdir(self._new_dir)
+            tempfile.tempdir = self._new_dir
+            
         self.__super_startTest(test)
         self._testtimes[test] = time.time()
 
@@ -632,6 +649,7 @@
     global GUI
     global TRACE
     global REFCOUNT
+    global PATCH_TEMPFILE
     global debug
     global debugger
     global build
@@ -655,6 +673,7 @@
     GUI = False
     TRACE = False
     REFCOUNT = False
+    PATCH_TEMPFILE = False
     debug = False # Don't collect test results; simply let tests crash
     debugger = False
     build = False
@@ -672,7 +691,7 @@
     test_dir = None
 
     try:
-        opts, args = getopt.getopt(argv[1:], "a:bBcdDfg:G:hLmprtTuv",
+        opts, args = getopt.getopt(argv[1:], "a:bBcdDfg:G:hLmnprtTuv",
                                    ["all", "help", "libdir=", "times=",
                                     "keepbytecode", "dir="])
     except getopt.error, msg:
@@ -719,6 +738,8 @@
             LOOP = 1
         elif k == "-m":
             GUI = "minimal"
+        elif k == "-n":
+            PATCH_TEMPFILE = True
         elif k == "-p":
             progress = True
         elif k == "-r":




More information about the Zodb-checkins mailing list