I would like to test the following Python function using pytest:
def increase_by_one()
n = int(input())
return n + 1
How can I write to the stdin/user input request within a function, for testing purposes?
I would like to test the following Python function using pytest:
def increase_by_one()
n = int(input())
return n + 1
How can I write to the stdin/user input request within a function, for testing purposes?
You can write your own input()
function which will return a fix string
.
save_it = input
input = lambda: 'your_simulated_input'
def test():
s = input() # returns 'your_simulated_input'
...