【发布时间】:2021-09-05 13:57:28
【问题描述】:
假设我有一个函数,它有两个相似的函数调用:
def foo():
test = one_func("SELECT * from Users;")
test1 = one_func("SELECT * from Addresses;")
return test, test1
如何修补这些功能内容?这是我的尝试:
@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;")
但我认为这种方法将 one_func 作为一个整体修补每个函数。结果:
def foo():
test = one_func("SELECT * from TestUsers;")
test1 = one_func("SELECT * from TestUsers;")
return test, test1
然后在下一行
def foo():
test = one_func("SELECT * from TestAddresses;")
test1 = one_func("SELECT * from TestAddresses;")
return test, test1
我希望在修补函数中发生的事情是。
def foo():
test = one_func("SELECT * from TestUsers;")
test1 = one_func("SELECT * from TestAddresses;")
return test, test1
【问题讨论】:
标签: sqlalchemy python-unittest python-unittest.mock