模拟数据库查询:我正在尝试模拟数据库查询并断言调用了save,但是断言失败。有人可以帮忙吗?
models.py
import peewee
class A():
human = CharField()
Age = CharField()
app.py
def get_A():
return models.select().where(models.A.Age="5")
def update_A():
age = get_A()
for i in age:
i.Age = 10
i.save()
test.py
def build_mock_A():
a = A()
a.human = "hath"
a.Age. = 5
return a
@patch('app.get_A')
def test_A(self,mock_get_A):
mock_get_A.return_value = build_mock_A()
app.update_A()
mock_get_A.save.assert_called_once()
错误:
raise AssertionError(msg)
AssertionError: Expected 'save' to have been called once. Called 0 times.