Substituting the built-in input function's value with a string is often used to test whether a method has the expected response to that input. A tool like monkeypatch would be used to do this, then we'd assert that calling the method returns the expected value.
Even when you call another method inside the method, if the second one has a predictable return value, you can use a similar approach.
Now, what if that method's expected behaviour is to call a method which also asks for input? The aim is to make sure that the program reached that second input prompt (confirming the first input had the expected result). Is there a way to assert this alone?
Example:
class TwoInputs:
def method_a(self):
self.action = input("Enter something: ")
if self.action == "jump":
self.method_b()
self.method_a()
elif self.action == "exit":
quit()
def method_b(self):
while True:
self.action = input("Enter some other thing: ")
if self.action == "1":
print("Hello world.")
break
else:
print("Invalid input.")
In the above context, how would you test that method_a successfully calls method_b, and just end the test there? If I were to monkeypatch input by changing it to "jump", then simply call method_a, that same input would be picked up as invalid in method_b, which then would loop continuously.