Which assertion verifies that a mock was called exactly once with specific arguments?
Options
assert mock.called is True and mock.count == 1mock.assert_called_once_with(42, retry=True)(Correct option)assert mock(42, retry=True) is not Nonemock.verify(42, retry=True, times=1)
Answer
mock.assert_called_once_with(42, retry=True)
Why
unittest.mock objects record every call made to them. assert_called_once_with(...) fails if the mock was called zero times, more than once, or with different arguments.
Other useful ones: assert_called_with (last call), assert_not_called(), and mock.call_args_list to inspect every call.
Remember
Check how a mock was called with assert_called_once_with.