# Include prefix 'called\_' in list of forbidden method prefixes for mock objects in unsafe mode

**URL:** <https://discuss.python.org/t/include-prefix-called-in-list-of-forbidden-method-prefixes-for-mock-objects-in-unsafe-mode/22249>\
**Category:** Ideas\
**Tags:** stdlib\
**Created:** [December 28, 2022, 12:58pm UTC](https://discuss.python.org/t/include-prefix-called-in-list-of-forbidden-method-prefixes-for-mock-objects-in-unsafe-mode/22249 "2022-12-28T12:58:14Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![cklein](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cklein/32/10359_2.png) [@cklein](https://discuss.python.org/u/cklein)\
**Post date:** [December 28, 2022, 2:09pm UTC](https://discuss.python.org/t/include-prefix-called-in-list-of-forbidden-method-prefixes-for-mock-objects-in-unsafe-mode/22249/4 "2022-12-28T14:09:33Z")

</div>

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:

```auto
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:

```auto
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)

```

---

_[View the full topic](https://discuss.python.org/t/include-prefix-called-in-list-of-forbidden-method-prefixes-for-mock-objects-in-unsafe-mode/22249)._
