[Python-checkins] commit of r41859 - python/trunk/Lib/test/test_logging.py

tim.peters python-checkins at python.org
Fri Dec 30 21:46:25 CET 2005


Author: tim.peters
Date: Fri Dec 30 21:46:23 2005
New Revision: 41859

Modified:
   python/trunk/Lib/test/test_logging.py
Log:
test_main():  Restore the original root logger level after running
the tests.  This stops the confusing/annoying:

    No handlers could be found for logger "cookielib"

message we got whenever some test running after test_logging
happened to use cookielib.py (when not using regrtest's -r,
this happened during test_urllib2; when using -r, it varied).


Modified: python/trunk/Lib/test/test_logging.py
==============================================================================
--- python/trunk/Lib/test/test_logging.py	(original)
+++ python/trunk/Lib/test/test_logging.py	Fri Dec 30 21:46:23 2005
@@ -487,11 +487,20 @@
         # or a Mac OS X box which supports very little locale stuff at all
         original_locale = None
 
+    # Save and restore the original root logger level across the tests.
+    # Otherwise, e.g., if any test using cookielib runs after test_logging,
+    # cookielib's debug-level logger tries to log messages, leading to
+    # confusing:
+    #    No handlers could be found for logger "cookielib"
+    # output while the tests are running.
+    root_logger = logging.getLogger("")
+    original_logging_level = root_logger.getEffectiveLevel()
     try:
         test_main_inner()
     finally:
         if original_locale is not None:
             locale.setlocale(locale.LC_ALL, original_locale)
+        root_logger.setLevel(original_logging_level)
 
 if __name__ == "__main__":
     sys.stdout.write("test_logging\n")


More information about the Python-checkins mailing list