Skip to content

Instantly share code, notes, and snippets.

@oprypin
Created September 2, 2022 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oprypin/46d06673473f8c435b3bd0d96a2c042b to your computer and use it in GitHub Desktop.
Save oprypin/46d06673473f8c435b3bd0d96a2c042b to your computer and use it in GitHub Desktop.
Disallow unexpected logging messages in Python unittest
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