[Zodb-checkins] CVS: ZODB3/zLOG/tests - testzLog.py:1.12.32.2
Tim Peters
tim.one at comcast.net
Mon Sep 15 12:32:45 EDT 2003
Update of /cvs-repository/ZODB3/zLOG/tests
In directory cvs.zope.org:/tmp/cvs-serv30171/zLOG/tests
Modified Files:
Tag: ZODB3-3_2-branch
testzLog.py
Log Message:
Horrid hackery so that these tests stop leaving behind junk log files
on Windows.
=== ZODB3/zLOG/tests/testzLog.py 1.12.32.1 => 1.12.32.2 ===
--- ZODB3/zLOG/tests/testzLog.py:1.12.32.1 Mon Sep 15 11:45:29 2003
+++ ZODB3/zLOG/tests/testzLog.py Mon Sep 15 12:32:39 2003
@@ -17,6 +17,7 @@
import tempfile
import unittest
import zLOG
+import logging
severity_string = {
-300: 'TRACE',
@@ -50,16 +51,22 @@
self.wipeEnvironment()
self.path = tempfile.mktemp()
self._severity = 0
+ # Windows cannot remove a file that's open. The logging code
+ # keeps the log file open, and I can't find an advertised API
+ # to tell the logger to close a log file. So here we cheat:
+ # tearDown() will close and remove all the handlers that pop
+ # into existence after setUp() runs. This breaks into internals,
+ # but I couldn't find a sane way to do it.
+ self.handlers = logging._handlers.keys() # capture current handlers
def tearDown(self):
- try:
- os.remove(self.path)
- except:
- # XXX We shouldn't hide the error. On Windows this in fact
- # XXX leaves the log file behind, because the logging module
- # XXX still has it open, and you can't delete an open file
- # XXX on Windows.
- pass
+ # Close and remove all the handlers that came into existence
+ # since setUp ran.
+ for h in logging._handlers.keys():
+ if h not in self.handlers:
+ h.close()
+ del logging._handlers[h]
+ os.remove(self.path)
self.wipeEnvironment()
def setLog(self, severity=0):
More information about the Zodb-checkins
mailing list