我正在使用带有 Python 2.7 的 MagicMock 来模拟对象。我正在模拟的其中一个类具有属性,其中一个TypeError
在某些情况下可以引发 a。
我想嘲笑这种行为,但我不知道如何:
del my_mock.my_property
将导致AttributeError
ifmy_property
被访问,但我需要一个TypeError
.my_mock.my_property = MagicMock(side_effect=TypeError)
导致TypeError
whenmy_property
is called,但不是仅在访问时。
我该怎么做?