Using Python mock to spy on calls to an existing object

I seem to have stumbled across the solution:

import mock

class A(object):
    def meth(self, a):
        return a
a = A()
ma = mock.Mock(wraps=a)

Seems to work okay for functions, methods and properties, but not for class or instance attributes.

See the documentation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)