Description
Feature or enhancement
Proposal:
Running this:
import unittest
from unittest.mock import Mock, call
class TestCase(unittest.TestCase):
def test_thing(self):
mock = Mock()
mock.assert_has_calls([call(a=1)])
unittest.main()
currently gives this test failure message:
AssertionError: Calls not found.
Expected: [call(a=1)]
This message does not imply that there were no calls. I propose that the test failure message is instead this:
AssertionError: Calls not found.
Expected: [call(a=1)]
Actual: []
The "Actual" list is already displayed if there are calls. It's only excluded if there are no calls.
The logic that causes an empty list not to be displayed is in the _calls_repr
method. For the other usages - assert_called_once_with
, assert_called_once
, and assert_not_called
- the number of calls is displayed directly in the error message so it already says that there are no calls. This makes me think the current behaviour of assert_has_calls
is just an oversight rather than intentional behaviour.
I'd be happy to open a PR for this.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response