Edit: I am flagging my own question as duplicate. My problem has a similar solution to this thread How to test a function with input call?.
I have a question regarding unit tests in python.
I have implemented the following function:
def prompt():
while True:
try:
choice = input("What do you want to do? ")
except EOFError:
exit("Program Terminated.")
except KeyboardInterrupt:
exit("Program Terminated.")
if choice in ['1', '2', '3', '4', '0']:
return int(choice)
and to test it, I have:
def test_prompt():
assert prompt() ...
My question is, how do I test my prompt()
function with pytest
? So far, I don't have problems with my other functions since their return value does not depend on the user input.
PS: If this question is duplicated, can you pls drop the link and I'll give it a go. Thank you.