From: Ben Darnell Date: Sat, 9 Feb 2013 20:52:47 +0000 (-0500) Subject: Make LogTrapTestCase fail more gracefully in unknown logging configurations. X-Git-Tag: v3.0.0~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=534c55699eb23ecc590583751bab46e943009348;p=thirdparty%2Ftornado.git Make LogTrapTestCase fail more gracefully in unknown logging configurations. This allows LogTrapTestCases to be run under nose, which does its own log buffering. Closes #674 --- diff --git a/tornado/testing.py b/tornado/testing.py index 803c35bed..ff373970c 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -398,21 +398,21 @@ class LogTrapTestCase(unittest.TestCase): This class assumes that only one log handler is configured and that it is a StreamHandler. This is true for both logging.basicConfig - and the "pretty logging" configured by tornado.options. + and the "pretty logging" configured by tornado.options. It is not + compatible with other log buffering mechanisms, such as those provided + by some test runners. """ def run(self, result=None): logger = logging.getLogger() - if len(logger.handlers) > 1: - # Multiple handlers have been defined. It gets messy to handle - # this, especially since the handlers may have different - # formatters. Just leave the logging alone in this case. - super(LogTrapTestCase, self).run(result) - return if not logger.handlers: logging.basicConfig() - self.assertEqual(len(logger.handlers), 1) handler = logger.handlers[0] - assert isinstance(handler, logging.StreamHandler) + if (len(logger.handlers) > 1 or + not isinstance(handler, logging.StreamHandler)): + # Logging has been configured in a way we don't recognize, + # so just leave it alone. + super(LogTrapTestCase, self).run(result) + return old_stream = handler.stream try: handler.stream = StringIO()