I need to test some python 3 code, and I got stuck testing function with few input()'s.
Example:
def two_answers():
if input("Input 'go' to proceed") != "go":
return two_answers()
else:
while input("Input 'bananas' to proceed") != "bananas":
print("What?!")
print("You've just gone bananas!")
For functions with one input i use:
def test_some_function(self):
codefile.input = lambda x: 'u'
codefile.some_function() . . . .
And then:
def teardown_method(self, method):
codefile.input = input
To revert inputs back.
But here it won't work. Help!
Aucun commentaire:
Enregistrer un commentaire