说我有一个看起来像这样的课:
class ThingToMock(Command):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
它基本上是数据的读取器/容器。我该如何在pytest中模拟呢?说它所在的路径是文件夹d/c/e
我有这个:
@pytest.fixture(autouse=True)
def mock_thing(mocker):
return mocker.patch(
'd.c.e',
return_value={}
)
@pytest.fixture(autouse=True)
def mock_service_thing(mocker):
return mocker.patch(
'd.c.e.f.RealService',
)
我后来想在View中写一个测试,内容为:
client.get(f'some/path')
mock_service_thing.assert_called_once_with(mock_thing.a, mock_thing.b, mock_thing.c)
我该怎么做?