尝试使用pytest mocker.patch,但似乎该补丁实际上未在我的任何测试中应用。我在错误地使用嘲笑吗?
tests / test_unit.py
import pytest
def test_get_item(self, client, mocker):
"""Tests get api can get item by ID"""
item = [{'id': 1,
'data': 'test'}]
patch = mocker.patch('helper.import_item_id',
return_value=item)
id = item[0]['id']
with application.test_request_context():
res = client.get(url_for('get_item', id=id))
result = json.loads(res.get_data())
patch.assert_called_with(id)
assert res.status_code == 200
helper.py(在根项目文件夹中)
def import_item_id(id):
"""Imports CSV data to df and returns
a item list' for a given id"""
items = import_data()
this_recipe = items.loc[items['id'] == id]
return this_item.to_dict('records')
它的运行就像没有应用该模拟一样,即assert_call_with失败,并且响应状态代码为200。