Author dandiez
Recipients dandiez
Date 2021-11-06.12:08:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1636200532.3.0.526903352151.issue45737@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-11-06 12:08:52dandiezsetrecipients: + dandiez
2021-11-06 12:08:52dandiezsetmessageid: <1636200532.3.0.526903352151.issue45737@roundup.psfhosted.org>
2021-11-06 12:08:52dandiezlinkissue45737 messages
2021-11-06 12:08:52dandiezcreate