I'm testing a method in python that accepts input from a console menu and then launches a method depending on the input. For some reason, my test fails to launch when a number is used in the test, but not a string. This doesn't occur in the normal flow of my python script.
Here are my two tests:
def test_invalid(self):
out = StringIO()
sys.stdout = out
main.launch_menu_choice("hello")
output = out.getvalue().strip()
assert output == 'Invalid selection, please try again.'
def test_one(self):
out = StringIO()
sys.stdout = out
main.launch_menu_choice('1')
output = out.getvalue().strip()
print output
assert output == 'where do you want to load your file: '
part of my code that I'm testing
def launch_menu_choice(choice):
if choice == '':
main_menu_actions['main_menu']()
else:
try:
main_menu_actions[choice]()
except KeyError:
print "Invalid selection, please try again.\n"
return
def load():
print "where do you want to load your file: "
path = raw_input(" >> ")
...
return
main_menu_actions is a dict. 1 is add. For some reason test_invalid works fine while test invalid hangs while it says it is launching unittests. I don't understand what is happening.