I want to be able to see how classes are instantiated and I want to see how how methods of that class are used. I can accomplish the first goal, but, the code below demonstrates how I can't spy on the method calls. The final assert fails.
import mock
class A:
def __init__(self, some_arg):
print("constructor")
def f(self, some_var):
print(some_var)
p = mock.patch('__main__.A', wraps=A)
m = p.start()
A = m
a = A('something')
a.f('my_arg')
assert mock.call('something') in m.mock_calls
assert m.method_calls # This fails, call to f is not tracked
If I use autospec=True I can see the method calls, but then the actual method isn't called. I want the actual code to run, I just want to spy on it.
I can't do something like http://wesmckinney.com/blog/spying-with-python-mocks/ because I don't have an instance of the class.