unittest.mock.Mock.assert_called_once_with()

assert_called_once_with(*args, **kwargs)

Assert that the mock was called exactly once and with the specified arguments.

1
2
3
4
5
6
7
8
>>> mock = Mock(return_value=None)
>>> mock('foo', bar='baz')
>>> mock.assert_called_once_with('foo', bar='baz')
>>> mock('foo', bar='baz')
>>> mock.assert_called_once_with('foo', bar='baz')
Traceback (most recent call last):
  ...
AssertionError: Expected 'mock' to be called once. Called 2 times.
doc_python
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.