Forked from famousgarkin/python-pytest-input-faking.py
Created
September 16, 2016 22:28
-
-
Save shamrt/9216403f42538a97162858cf0ab2c2f5 to your computer and use it in GitHub Desktop.
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 os | |
def test_user_input(monkeypatch): | |
inputs = [10, 'y'] | |
input_generator = (i for i in inputs) | |
monkeypatch.setattr('__builtin__.raw_input', lambda prompt: next(input_generator)) | |
assert raw_input('how many?') == 10 | |
assert raw_input('you sure?') == 'y' | |
def test_file_input(tmpdir): | |
fixture = tmpdir.join('fixture.txt') | |
fixture.write(os.linesep.join(['1', '2', '3'])) | |
fixture_path = str(fixture.realpath()) | |
with open(fixture_path) as f: | |
assert f.readline() == '1' + os.linesep | |
def test_environment_input(monkeypatch): | |
monkeypatch.setenv('STAGING', 1) | |
assert os.environ['STAGING'] == '1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment