Skip to content

Instantly share code, notes, and snippets.

@ahojukka5
Created October 11, 2020 16:31
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 ahojukka5/8b2e34fc9f34e204462bd8ed4f2cac46 to your computer and use it in GitHub Desktop.
Save ahojukka5/8b2e34fc9f34e204462bd8ed4f2cac46 to your computer and use it in GitHub Desktop.
Testing function with stdin and stdout
from io import StringIO
def adding():
x = int(input('Anna luku 1'))
y = int(input('Anna luku 2'))
print("Summa on %d" % (x + y))
def test_adding(monkeypatch, capsys):
number_inputs = StringIO('2\n3\n')
monkeypatch.setattr('sys.stdin', number_inputs)
adding()
captured = capsys.readouterr()
assert "Summa on 5" in captured.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment