Tôi có một lớp:Làm cách nào để giả lập thuộc tính lớp với mox?
class MyClass(object):
@property
def myproperty(self):
return 'hello'
Sử dụng mox
và py.test
, làm thế nào để tôi thử ra myproperty
?
Tôi đã thử:
mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty = 'goodbye'
và
mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty.AndReturns('goodbye')
nhưng cả hai thất bại với AttributeError: can't set attribute
.
Vui lòng sử dụng Tên viết hoa phía trên cho Lớp học. –