Let's say I have a function that has two similar function calls:
def foo():
test = one_func("SELECT * from Users;")
test1 = one_func("SELECT * from Addresses;")
return test, test1
How do I patch each of these function contents? Here's my attempt:
@patch('one_func')
def test_foo(self, mock_one_func):
mock_one_func.return_value = one_func("SELECT * from TestUsers;")
mock_one_func.return_value = one_func("SELECT * from TestAddresses;")
But I think this method patches one_func
as a whole per function. Which results to:
def foo():
test = one_func("SELECT * from TestUsers;")
test1 = one_func("SELECT * from TestUsers;")
return test, test1
Then on the next line
def foo():
test = one_func("SELECT * from TestAddresses;")
test1 = one_func("SELECT * from TestAddresses;")
return test, test1
What I want to happen in the patched function is.
def foo():
test = one_func("SELECT * from TestUsers;")
test1 = one_func("SELECT * from TestAddresses;")
return test, test1