Issue #12167: packaging.tests.support, LoggingCatcher restores correctly the

log level. Avoid also calls to .addCleanup() in setUp().
This commit is contained in:
Victor Stinner 2011-05-24 13:59:21 +02:00
parent 99c8b16143
commit 79d1b1ce3f
1 changed files with 2 additions and 1 deletions

View File

@ -71,8 +71,8 @@ class LoggingCatcher:
def setUp(self): def setUp(self):
super(LoggingCatcher, self).setUp() super(LoggingCatcher, self).setUp()
self.loghandler = handler = _TestHandler() self.loghandler = handler = _TestHandler()
self.old_level = logger.level
logger.addHandler(handler) logger.addHandler(handler)
self.addCleanup(logger.setLevel, logger.level)
logger.setLevel(logging.DEBUG) # we want all messages logger.setLevel(logging.DEBUG) # we want all messages
def tearDown(self): def tearDown(self):
@ -84,6 +84,7 @@ class LoggingCatcher:
for ref in weakref.getweakrefs(handler): for ref in weakref.getweakrefs(handler):
logging._removeHandlerRef(ref) logging._removeHandlerRef(ref)
del self.loghandler del self.loghandler
logger.setLevel(self.old_level)
super(LoggingCatcher, self).tearDown() super(LoggingCatcher, self).tearDown()
def get_logs(self, *levels): def get_logs(self, *levels):