Last active
January 2, 2016 14:39
-
-
Save jaapz/8317729 to your computer and use it in GitHub Desktop.
Monkeypatch builtins for use in py.tests
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 __builtin__ | |
def test_raw_input(monkeypatch): | |
""" Get user input without actually having a user type letters using monkeypatch """ | |
def mock_raw_input(*args, **kwargs): | |
""" Act like someone just typed 'yolo'. """ | |
return 'yolo'; | |
monkeypatch.setattr(__builtin__, 'raw_input', mock_raw_input) | |
# retval should now contain 'yolo' | |
retval = raw_input() | |
assert retval == 'yolo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment