From: Ben Darnell Date: Sun, 11 Jun 2017 03:00:08 +0000 (-0400) Subject: test: Make log detection sensitive to info logs X-Git-Tag: v5.0.0~71^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2083%2Fhead;p=thirdparty%2Ftornado.git test: Make log detection sensitive to info logs Silence one in httpserver_test --- diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index a3b86ac99..4444a3922 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -408,12 +408,13 @@ class HTTPServerRawTest(AsyncHTTPTestCase): self.wait() def test_malformed_first_line_response(self): - self.stream.write(b'asdf\r\n\r\n') - read_stream_body(self.stream, self.stop) - start_line, headers, response = self.wait() - self.assertEqual('HTTP/1.1', start_line.version) - self.assertEqual(400, start_line.code) - self.assertEqual('Bad Request', start_line.reason) + with ExpectLog(gen_log, '.*Malformed HTTP request line'): + self.stream.write(b'asdf\r\n\r\n') + read_stream_body(self.stream, self.stop) + start_line, headers, response = self.wait() + self.assertEqual('HTTP/1.1', start_line.version) + self.assertEqual(400, start_line.code) + self.assertEqual('Bad Request', start_line.reason) def test_malformed_first_line_log(self): with ExpectLog(gen_log, '.*Malformed HTTP request line'): diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index b81c5f225..dc702eda4 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -80,13 +80,15 @@ class LogCounter(logging.Filter): def __init__(self, *args, **kwargs): # Can't use super() because logging.Filter is an old-style class in py26 logging.Filter.__init__(self, *args, **kwargs) - self.warning_count = self.error_count = 0 + self.info_count = 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 + elif record.levelno >= logging.INFO: + self.info_count += 1 return True @@ -177,12 +179,15 @@ def main(): 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) + # The tests should run clean; consider it a failure if they + # logged anything at info level or above (except for the one + # allowed info message "PASS") + if (log_counter.info_count > 1 or + log_counter.warning_count > 0 or + log_counter.error_count > 0): + logging.error("logged %d infos, %d warnings, and %d errors", + log_counter.info_count, log_counter.warning_count, + log_counter.error_count) sys.exit(1)