用法:
mock_calls
mock_calls
记录all
调用模拟对象、其方法、魔术方法and
返回值模拟。>>> mock = MagicMock() >>> result = mock(1, 2, 3) >>> mock.first(a=3) <MagicMock name='mock.first()' id='...'> >>> mock.second() <MagicMock name='mock.second()' id='...'> >>> int(mock) 1 >>> result(1) <MagicMock name='mock()()' id='...'> >>> expected = [call(1, 2, 3), call.first(a=3), call.second(), ... call.__int__(), call()(1)] >>> mock.mock_calls == expected True
mock_calls
的成员是call
对象。这些可以解包为元组以获取各个参数。将调用视为元组。注意
记录
mock_calls
的方式意味着在进行嵌套调用的地方,不记录祖先调用的参数,因此总是比较相等:>>> mock = MagicMock() >>> mock.top(a=3).bottom() <MagicMock name='mock.top().bottom()' id='...'> >>> mock.mock_calls [call.top(a=3), call.top().bottom()] >>> mock.mock_calls[-1] == call.top(a=-1).bottom() True
相关用法
- Python unittest.mock.Mock.method_calls用法及代码示例
- Python unittest.mock.Mock.reset_mock用法及代码示例
- Python unittest.mock.Mock.__class__用法及代码示例
- Python unittest.mock.Mock.call_args用法及代码示例
- Python unittest.mock.Mock.call_args_list用法及代码示例
- Python unittest.mock.Mock.assert_called用法及代码示例
- Python unittest.mock.Mock.assert_not_called用法及代码示例
- Python unittest.mock.Mock.assert_has_calls用法及代码示例
- Python unittest.mock.Mock.configure_mock用法及代码示例
- Python unittest.mock.Mock.called用法及代码示例
- 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.call_count用法及代码示例
- 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.mock_calls。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。