logging: fix handler level restored incorrectly if caplog.set_level is called more than once
This commit is contained in:
parent
d69abff2c7
commit
b1354608cc
|
@ -0,0 +1 @@
|
|||
Fixed log-capturing level restored incorrectly if ``caplog.set_level`` is called more than once.
|
|
@ -439,6 +439,7 @@ class LogCaptureFixture:
|
|||
# Save the original log-level to restore it during teardown.
|
||||
self._initial_logger_levels.setdefault(logger, logger_obj.level)
|
||||
logger_obj.setLevel(level)
|
||||
if self._initial_handler_level is None:
|
||||
self._initial_handler_level = self.handler.level
|
||||
self.handler.setLevel(level)
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ def test_change_level_undos_handler_level(testdir: Testdir) -> None:
|
|||
|
||||
def test1(caplog):
|
||||
assert caplog.handler.level == 0
|
||||
caplog.set_level(9999)
|
||||
caplog.set_level(41)
|
||||
assert caplog.handler.level == 41
|
||||
|
||||
|
|
Loading…
Reference in New Issue