[New-bugs-announce] [issue45737] assertLogs to optionally not disable existing handlers

Daniel report at bugs.python.org
Sat Nov 6 08:08:52 EDT 2021


New submission from Daniel <3daniel at hotmail.com>:

At the moment, assertLogs removes the handlers attached to the logger.
In general this is good, because it reduces message spamming in the test logs.
However, if the code being tested is relying on a handler to do something, then the test fails because the handler is being removed.
This leads to the situation that the same exact test must be run twice:
- first time within the context manager, to assert that specific messages were logged (using `with self.assertLogs()`)
- second time, without the assertLogs to ensure the code that uses a handler does the right thing

The proposal is to have `self.assertLogs()` accept a key word argument such as `keep_handlers=False`, which can be set to True, whenever the handlers should be preserved.
It would probably be also useful to add a note in the documentation that makes users aware that the existing handlers will be removed.

----------
messages: 405858
nosy: dandiez
priority: normal
severity: normal
status: open
title: assertLogs to optionally not disable existing handlers
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45737>
_______________________________________


More information about the New-bugs-announce mailing list