Created
September 2, 2022 22:17
-
-
Save oprypin/46d06673473f8c435b3bd0d96a2c042b to your computer and use it in GitHub Desktop.
Disallow unexpected logging messages in Python unittest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
class DisallowLogsHandler(logging.Handler): | |
def emit(self, record): | |
raise AssertionError(f'Unexpected log: "{self.format(record)}"') | |
logging.lastResort = DisallowLogsHandler(level=logging.WARNING) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment