【发布时间】:2011-01-31 12:45:18
【问题描述】:
我有一堂课:
class MyClass(object):
@property
def myproperty(self):
return 'hello'
使用mox 和py.test,我如何模拟出myproperty?
我试过了:
mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty = 'goodbye'
和
mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty.AndReturns('goodbye')
但两者都以AttributeError: can't set attribute 失败。
【问题讨论】:
-
请使用大写的类名。
标签: python mocking properties mox