def assert_called_with(self, /, *args, **kwargs):
"""assert that the last call was made with the specified arguments.
Raises an AssertionError if the args and keyword args passed in are
different to the last call to the mock."""
if self.call_args is None:
expected = self._format_mock_call_signature(args, kwargs)
actual = 'not called.'
error_message = ('expected call not found.nExpected: %snActual: %s'
% (expected, actual))
raise AssertionError(error_message)
我以前从未在python函数的参数中遇到过/
,并且这里似乎没有使用它(在mock库的mock.py中)。那么它是做什么的呢?
这用于表示/
之前的任何内容都是位置参数。请注意,像range
这样具有start, stop, and step
的函数不允许关键字参数,例如您不能执行range(stop = 3)
。这是因为在函数定义中使用了/
。点击这里查看进一步阐述