用法:
call_args
這是
None
(如果尚未調用模擬),或者是上次調用模擬的參數。這將采用元組的形式:第一個成員,也可以通過args
屬性訪問,是調用模擬的任何有序參數(或空元組),第二個成員也可以是通過kwargs
屬性訪問的是任何關鍵字參數(或空字典)。>>> mock = Mock(return_value=None) >>> print(mock.call_args) None >>> mock() >>> mock.call_args call() >>> mock.call_args == () True >>> mock(3, 4) >>> mock.call_args call(3, 4) >>> mock.call_args == ((3, 4),) True >>> mock.call_args.args (3, 4) >>> mock.call_args.kwargs {} >>> mock(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args call(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args.args (3, 4, 5) >>> mock.call_args.kwargs {'key': 'fish', 'next': 'w00t!'}
call_args
以及列表call_args_list
、method_calls
和mock_calls
的成員是call
對象。這些是元組,因此可以將它們解包以獲取單個參數並做出更複雜的斷言。將調用視為元組。在 3.8 版中更改:添加
args
和kwargs
特性。
相關用法
- Python unittest.mock.Mock.call_args_list用法及代碼示例
- Python unittest.mock.Mock.call_count用法及代碼示例
- Python unittest.mock.Mock.called用法及代碼示例
- Python unittest.mock.Mock.configure_mock用法及代碼示例
- Python unittest.mock.Mock.reset_mock用法及代碼示例
- Python unittest.mock.Mock.__class__用法及代碼示例
- Python unittest.mock.Mock.method_calls用法及代碼示例
- Python unittest.mock.Mock.assert_called用法及代碼示例
- Python unittest.mock.Mock.assert_not_called用法及代碼示例
- Python unittest.mock.Mock.mock_calls用法及代碼示例
- Python unittest.mock.Mock.assert_has_calls用法及代碼示例
- Python unittest.mock.Mock.side_effect用法及代碼示例
- Python unittest.mock.Mock.assert_called_once_with用法及代碼示例
- Python unittest.mock.Mock.assert_called_once用法及代碼示例
- Python unittest.mock.Mock.assert_any_call用法及代碼示例
- Python unittest.mock.Mock.assert_called_with用法及代碼示例
- Python unittest.mock.Mock.return_value用法及代碼示例
- Python unittest.mock.AsyncMock.assert_awaited_once_with用法及代碼示例
- Python unittest.mock.call用法及代碼示例
- Python unittest.mock.AsyncMock.assert_any_await用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 unittest.mock.Mock.call_args。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。