Created
October 11, 2020 16:31
-
-
Save ahojukka5/8b2e34fc9f34e204462bd8ed4f2cac46 to your computer and use it in GitHub Desktop.
Testing function with stdin and stdout
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
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