A follow on for this question.
I am accepting user input in a for loop and have written a test case, test_apple_record
. In this for loop, it queries a method self.dispatch_requested()
( not shown) which can randomly return True or False. Based on this answer, the code asks user for another input -- where the tray should be dispatched.
I am using the side_effect
argument for mock.patch
. How to automatically pass the hotel number as the user input using mock? I still want to continue passing the numbers [5, 6, 7]
to the for loop, but now also want to pass in the hotel number based on response by self.dispatch_requested()
thank you
class SomeClass(unittest.TestCase):
def apple_counter(self):
apple_record = {}
for i in range(3):
apple_tray = input("enter tray number:")
apple_record[apple_tray] = (i+1)*10
print("i=%d, apple_record=%s"%(i, apple_record))
if self.dispath_requested():
number = input("Enter Hotel number to dispatch this tray:")
update_hotel_record(number, apple_tray)
def update_hotel_record(self, number, tray):
self.hotel_record[number] = tray
def test_apple_record(self):
with mock.patch('builtins.input', side_effect=[5, 6, 7]):
self.apple_counter()