我正在尝试执行类似的事情:
mymock = Mock()
mymock.variable.side_effect = [1,2,3]
print mymock.variable # Should print 1
print mymock.variable # Should print 2
print mymock.variable # Should print 3
但是,我没有得到预期的结果。 我错过了什么?
仅当属性作为方法调用时,才适用side_effect
:
In [3]: mymock = Mock()
In [4]: mymock.variable.side_effect = [1,2,3]
In [5]: mymock.variable()
Out[5]: 1
In [6]: mymock.variable()
Out[6]: 2
In [7]: mymock.variable()
Out[7]: 3
没有类似的功能用于为属性分配值。