【发布时间】:2019-10-23 13:05:40
【问题描述】:
我正在尝试模拟我使用 mocker.patch.object 创建的另一个方法。但是我得到了AttributeError。刚开始使用 mocker,但还没有看到可以帮助解决这种情况的示例。
尝试了从 mocker 调用方法的不同方式。
在测试/test_unit.py 中
from pytest_mock import mocker
class TestApp:
def setup_method(self):
self.obj = ClassApi()
def test_class_api_method(self, client):
return_value = {'name': 'test'}
mocker.patch.object(self.obj, 'method_to_mock')
mocker.result(return_value)
在项目/服务中
class ClassApi:
def method_to_mock(self, input1):
...
return result
AttributeError: 'function' 对象没有属性 'patch'
【问题讨论】:
标签: python pytest api-design