How do I mock a class property with mox?

Posted by Harley on Stack Overflow See other posts from Stack Overflow or by Harley
Published on 2010-03-25T00:48:25Z Indexed on 2010/03/25 0:53 UTC
Read the original article Hit count: 484

Filed under:
|
|
|

I have a class:

class myclass(object):
    @property
    def myproperty(self):
        return 'hello'

Using mox and py.test, how do I mock out myproperty?

I've tried:

mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty = 'goodbye'

and

mock.StubOutWithMock(myclass, 'myproperty')
myclass.myproperty.AndReturns('goodbye')

but both fail with AttributeError: can't set attribute.

© Stack Overflow or respective owner

Related posts about python

Related posts about mox