I'm asking this question having viewed these 2 similar ones:
How to patch multiple repeated inputs in python unit test?
Python mock multiple return values
But neither satisfactorily gives me the answer I'm looking for.
I need to be able to patch multiple calls to input()
using the with statement rather than a decorator.
The reason for this is that the test I'm writing doesn't allow me to use a decorator, nor modify the signature of the test method to add the mocked input as in:
@mock.patch('builtins.input')
def test_myMethod(self, mocked_input):
mock_args = ['20', 100]
mocked_input.side_effect = mock_args
res = mymethod()
self.assertEqual(res, 120)
My question is how can I achieve the same effect using as with statement as in:
def test_myMethod(self):
with mock.patch('builtins.input', ...)
Any help would be greatly appreciated