21
class A():
    def tmp(self):
        print("hi")

def b(a):
    a.tmp()

To check if tmp method is called in b, the recommended way is

a = A()
a.tmp = MagicMock()
b(a)
a.tmp.assert_called()

But tmp here is being mocked away and is not resulting in a "hi" getting printed.

I would want my unit test to check if method tmp is called without mocking it away.

Is this possible?

I know this is not a standard thing to expect when writing unitests. But my use case (which is bit tricky) requires this.

4

2 に答える 2