就我而言,我有一个如下所示的函数:
# the ModelA is an ORM model here (peewee)
def my_func():
result1 = ModelA.select().where(
# some condition here
)
result2 = ModelA.select().where(
# some other condition here
)
# use the combination of result1 and 2 to do some thing and return result
我不知道如何在这里模拟查询。有两个问题:
我不知道如何模拟查询。有文章说:
mock.patch(some_path.ModelA) 作为 mock_model mock_model.select.where.return_value = 我期望的值
哪个不起作用
一种解决方法是将两个查询转换为两个函数。但我看不出有什么好处,除了容易 ut