The method doesn’t exist and therefore the return value is an instance of Mock. An instance of mock evaluates to true, which makes this a tautology test and thus gives a false sense of safety.
See this short snippet of the passing assertion:
In [1]: from unittest import mock
In [2]: m = mock.Mock()
In [3]: m.method(param=1)
Out[3]: <Mock name='mock.method()' id='4353968160'>
In [4]: m.method.called_once_with(arg=2)
Out[4]: <Mock name='mock.method.called_once_with()' id='4387616944'>
In [5]: assert m.method.called_once_with(arg=2)
When in fact the test should fail:
In [14]: m.method.assert_called_once_with(arg=2)
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In [14], line 1
----> 1 m.method.assert_called_once_with(arg=2)
File /opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/mock.py:941, in NonCallableMock.assert_called_once_with(self, *args, **kwargs)
936 msg = ("Expected '%s' to be called once. Called %s times.%s"
937 % (self._mock_name or 'mock',
938 self.call_count,
939 self._calls_repr()))
940 raise AssertionError(msg)
--> 941 return self.assert_called_with(*args, **kwargs)
File /opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/mock.py:929, in NonCallableMock.assert_called_with(self, *args, **kwargs)
927 if actual != expected:
928 cause = expected if isinstance(expected, Exception) else None
--> 929 raise AssertionError(_error_message()) from cause
AssertionError: expected call not found.
Expected: method(arg=2)
Actual: method(param=1)