]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Consider the tests failed if they log any non-filtered warnings or errors.
authorBen Darnell <ben@bendarnell.com>
Sat, 17 Jan 2015 21:37:49 +0000 (16:37 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 17 Jan 2015 21:37:49 +0000 (16:37 -0500)
tornado/test/runtests.py
tornado/testing.py

index 27cb18b1a23be8cf2274f7af4de03bdda2430251..371dfb3c9946f9c84f0c9168251a886e236a0594 100644 (file)
@@ -67,6 +67,20 @@ class TornadoTextTestRunner(unittest.TextTestRunner):
         return result
 
 
+class LogCounter(logging.Filter):
+    """Counts the number of WARNING or higher log records."""
+    def __init__(self, *args, **kwargs):
+        super(LogCounter, self).__init__(*args, **kwargs)
+        self.warning_count = self.error_count = 0
+
+    def filter(self, record):
+        if record.levelno >= logging.ERROR:
+            self.error_count += 1
+        elif record.levelno >= logging.WARNING:
+            self.warning_count += 1
+        return True
+
+
 def main():
     # The -W command-line option does not work in a virtualenv with
     # python 3 (as of virtualenv 1.7), so configure warnings
@@ -125,6 +139,10 @@ def main():
             IOLoop.configure(options.ioloop, **kwargs)
     add_parse_callback(configure_ioloop)
 
+    log_counter = LogCounter()
+    add_parse_callback(
+        lambda: logging.getLogger().handlers[0].addFilter(log_counter))
+
     import tornado.testing
     kwargs = {}
     if sys.version_info >= (3, 2):
@@ -135,7 +153,16 @@ def main():
         # detail.  http://bugs.python.org/issue15626
         kwargs['warnings'] = False
     kwargs['testRunner'] = TornadoTextTestRunner
-    tornado.testing.main(**kwargs)
+    try:
+        tornado.testing.main(**kwargs)
+    finally:
+        # The tests should run clean; consider it a failure if they logged
+        # any warnings or errors. We'd like to ban info logs too, but
+        # we can't count them cleanly due to interactions with LogTrapTestCase.
+        if log_counter.warning_count > 0 or log_counter.error_count > 0:
+            logging.error("logged %d warnings and %d errors",
+                          log_counter.warning_count, log_counter.error_count)
+            sys.exit(1)
 
 if __name__ == '__main__':
     main()
index 4511863b7f90d7be7386fdd43340480f0d3c3754..3d3bcf72b974d9cc0f8231982da00fef19766894 100644 (file)
@@ -543,6 +543,9 @@ class LogTrapTestCase(unittest.TestCase):
     `logging.basicConfig` 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.
+
+    .. deprecated:: 4.1
+       Use the unittest module's ``--buffer`` option instead, or `.ExpectLog`.
     """
     def run(self, result=None):
         logger = logging.getLogger()