diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2019-06-19 10:46:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-19 10:46:53 (GMT) |
commit | 015000165373f8db263ef5bc682f02d74e5782ac (patch) | |
tree | bf8ffd599968696577658cfcb0b687762031649f /Lib/test/test_logging.py | |
parent | 987a0dcfa1302df6c1ed8cf14762dc18628e3f33 (diff) | |
download | cpython-015000165373f8db263ef5bc682f02d74e5782ac.zip cpython-015000165373f8db263ef5bc682f02d74e5782ac.tar.gz cpython-015000165373f8db263ef5bc682f02d74e5782ac.tar.bz2 |
bpo-37258: Not a bug, but added a unit test and updated documentation. (GH-14229)
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index ac8919d..6507d79 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -4172,6 +4172,37 @@ class ModuleLevelMiscTest(BaseTest): logging.setLoggerClass(logging.Logger) self.assertEqual(logging.getLoggerClass(), logging.Logger) + def test_subclass_logger_cache(self): + # bpo-37258 + message = [] + + class MyLogger(logging.getLoggerClass()): + def __init__(self, name='MyLogger', level=logging.NOTSET): + super().__init__(name, level) + message.append('initialized') + + logging.setLoggerClass(MyLogger) + logger = logging.getLogger('just_some_logger') + self.assertEqual(message, ['initialized']) + stream = io.StringIO() + h = logging.StreamHandler(stream) + logger.addHandler(h) + try: + logger.setLevel(logging.DEBUG) + logger.debug("hello") + self.assertEqual(stream.getvalue().strip(), "hello") + + stream.truncate(0) + stream.seek(0) + + logger.setLevel(logging.INFO) + logger.debug("hello") + self.assertEqual(stream.getvalue(), "") + finally: + logger.removeHandler(h) + h.close() + logging.setLoggerClass(logging.Logger) + @support.requires_type_collecting def test_logging_at_shutdown(self): # Issue #20037 |