mirror of
https://github.com/python/cpython.git
synced 2025-12-05 00:52:25 +00:00
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).
This commit is contained in:
parent
1b27f86411
commit
0cdc3d884e
1 changed files with 9 additions and 0 deletions
|
|
@ -487,11 +487,20 @@ def test_main():
|
||||||
# or a Mac OS X box which supports very little locale stuff at all
|
# or a Mac OS X box which supports very little locale stuff at all
|
||||||
original_locale = None
|
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:
|
try:
|
||||||
test_main_inner()
|
test_main_inner()
|
||||||
finally:
|
finally:
|
||||||
if original_locale is not None:
|
if original_locale is not None:
|
||||||
locale.setlocale(locale.LC_ALL, original_locale)
|
locale.setlocale(locale.LC_ALL, original_locale)
|
||||||
|
root_logger.setLevel(original_logging_level)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.stdout.write("test_logging\n")
|
sys.stdout.write("test_logging\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue