Skip to content

Instantly share code, notes, and snippets.

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 shamrt/9216403f42538a97162858cf0ab2c2f5 to your computer and use it in GitHub Desktop.
Save shamrt/9216403f42538a97162858cf0ab2c2f5 to your computer and use it in GitHub Desktop.
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