I’m trying to mock the __call__
method of a mock object so that when I call this object as object()
it returns a certain value. My code so far is:
from pytest import Mock
my_mock = Mock()
mock_output = "mock"
my_mock.__call__ = Mock(return_value=mock_output)
The problem is that:
my_mock.__call__() # prints "mock"
my_mock() # prints "<Mock name='mock()' id='140016400530976'>"
But in my tested code I use the second way of calling the __call__
method.
What can I do to get the same behavior in both cases?