0
在我FooClass
对象我有self.mylist
它由MyObject
S和正在从一些数据库查询创建的列表。
到目前为止,在我的测试中,我一直在使用pytest
夹具:嘲讽在Python
@fixture
def mock_mylist():
foo = FooClass()
foo.mylist = MagicMock()
return foo
它工作得很好,当我不得不测试方法,在我需要的只是mylist
“有些名单”。然而,该方法之一是依靠mylist
并做一些检查,像
for el in mylist:
if el.MyObject.a == 1 and el.MyObject.b == 2 and...
#compare el.MyObject.c to some external value and process...
综上所述,我需要嘲笑MyObject
测试mylist
,但我想以某种方式定义一些嘲笑MyObject
属性。