[Tutor] how to unittest cli input
Alex Kleider
akleider at sonic.net
Sun Oct 11 02:41:17 CEST 2015
"""
I'm trying to follow a test driven development paradigm (using
unittest) but can't figure out how to test functions that collect
info from the command line such as the following.
"""
# collect.py
def collect_data():
ret = {}
ret['first'] = input("Enter your first name: ")
ret['last'] = input("Enter your last name: ")
ret['phone'] = input("Your mobile phone #: ")
return ret
def main():
print(collect_data())
if __name__ == "__main__":
main()
The following works:
$ python3 collect.py < cli_input
# cli_input
Alex
Kleider
415/868-1920
... but I don't know how to make it a unittest.
Thanks in advance for any suggestions.
Alex
More information about the Tutor
mailing list