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