Doctesting functions that receive and display user input - Python (tearing my hair out)
- by GlenCrawford
Howdy!
I am currently writing a small application with Python (3.1), and like a good little boy, I am doctesting as I go. However, I've come across a method that I can't seem to doctest. It contains an input(), an because of that, I'm not entirely sure what to place in the "expecting" portion of the doctest.
Example code to illustrate my problem follows:
"""
>>> getFiveNums()
Howdy. Please enter five numbers, hit <enter> after each one
Please type in a number:
Please type in a number:
Please type in a number:
Please type in a number:
Please type in a number:
"""
import doctest
numbers = list()
# stores 5 user-entered numbers (strings, for now) in a list
def getFiveNums():
print("Howdy. Please enter five numbers, hit <enter> after each one")
for i in range(5):
newNum = input("Please type in a number:")
numbers.append(newNum)
print("Here are your numbers: ", numbers)
if __name__ == "__main__":
doctest.testmod(verbose=True)
When running the doctests, the program stops executing immediately after printing the "Expecting" section, waits for me to enter five numbers one after another (without prompts), and then continues. As shown below:
I don't know what, if anything, I can place in the Expecting section of my doctest to be able to test a method that receives and then displays user input. So my question (finally) is, is this function doctestable?