这是我想做的一个非常简化的版本。假设我有一门课:
class Paint():
def __init__(self):
# None, or a string.
self.color = None
def brush(self):
self.color = 'blue'
self.color = None
然后在我的单元测试中,我希望执行以下操作:
p = Paint()
p.brush()
# Hypothetical verification
assert tuples = p.color.mock_assignments
assert tuples[0] == 'blue'
assert tuples[1] == None
我想创建一个真正的Paint()对象,但模拟出成员变量color
。
我想验证调用brush()时color
是否被设置为某个值,然后又被设置回无。我该怎么做
我使用的是Ubuntu18.04,Python3.7,使用的是模拟软件包
谢谢
根据讨论,这里是一个模拟我会做这样的情况
我已经修改了您的代码,假设使用了另一个函数来使用更改的
self.color
值相关问题 更多 >
编程相关推荐