Last active
March 19, 2020 02:00
-
-
Save dhilst/b4039e158545f2d8ae5b054e69720585 to your computer and use it in GitHub Desktop.
monkey patch example
This file contains 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
from unittest import TestCase, main | |
from unittest.mock import patch | |
# import monkeypatch | |
from logging import getLogger | |
log = getLogger('foo') | |
if __name__ == '__main__': | |
log.error("some log message") |
This file contains 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 | |
original_getLogger = logging.getLogger | |
def patched_getLogger(name): | |
print("Calling getLogger") | |
return original_getLogger(name) | |
logging.getLogger = patched_getLogger | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment