[Zodb-checkins] CVS: ZODB3 - test.py:1.24.4.1
Jeremy Hylton
jeremy at zope.com
Sat Sep 6 23:27:02 EDT 2003
Update of /cvs-repository/ZODB3
In directory cvs.zope.org:/tmp/cvs-serv7536
Modified Files:
Tag: ZODB3-3_2-branch
test.py
Log Message:
improvement for debugging temp files left behind:
tempfile uses a different temp directory for each test.
Not sure this will work on Windows.
=== ZODB3/test.py 1.24 => 1.24.4.1 ===
--- ZODB3/test.py:1.24 Thu Apr 24 11:53:00 2003
+++ ZODB3/test.py Sat Sep 6 22:27:01 2003
@@ -144,8 +144,10 @@
import pdb
import sys
import time
-import traceback
+import errno
+import tempfile
import unittest
+import traceback
from distutils.util import get_platform
@@ -182,6 +184,7 @@
def stopTest(self, test):
self._testtimes[test] = time.time() - self._testtimes[test]
+ self.deleteTempDir()
if gc.garbage:
print "The following test left garbage:"
print test
@@ -231,7 +234,29 @@
self._lastWidth = width
self.stream.flush()
self.__super_startTest(test)
+ self.createTempDir(test)
self._testtimes[test] = time.time()
+
+ def createTempDir(self, test):
+ # Set test-specific temp directory
+ name = test._TestCase__testMethodName # blast it
+ tempfile.tempdir = self.tempdir = os.path.join("/tmp", name)
+ try:
+ os.mkdir(self.tempdir)
+ except OSError, err:
+ # If the directory already exists, that's fine. Otherwise
+ # the test is going to fail if it uses a tempfile, so raise.
+ if err[0] != errno.EEXIST:
+ raise
+
+ def deleteTempDir(self):
+ try:
+ os.rmdir(self.tempdir)
+ except OSError, err:
+ # If there's an error other than a non-empty directory, print
+ # a warning and continue.
+ if err[0] != errno.ENOTEMPTY:
+ print err
def getShortDescription(self, test):
s = self.getDescription(test)
More information about the Zodb-checkins
mailing list