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
""" This is a convenient way to monkeypatch a method or attribute of a Python | |
object. This is great for situations where you want to modify a global | |
object within a limited scope, i.e., your typical class or module when | |
testing. This was tested and works with Python 2.7 and 3.4. """ | |
import contextlib | |
@contextlib.contextmanager | |
def monkeypatched(object, name, patch): | |
""" Temporarily monkeypatches an object. """ |