用法:
__class__
通常,對象的
__class__
屬性將返回其類型。對於帶有spec
的模擬對象,__class__
會返回規範類。這允許模擬對象通過isinstance()
測試它們正在替換/偽裝的對象:>>> mock = Mock(spec=3) >>> isinstance(mock, int) True
__class__
可分配給,這允許模擬通過isinstance()
檢查,而不會強製您使用規範:>>> mock = Mock() >>> mock.__class__ = dict >>> isinstance(mock, dict) True
相關用法
- Python unittest.mock.Mock.reset_mock用法及代碼示例
- Python unittest.mock.Mock.call_args用法及代碼示例
- Python unittest.mock.Mock.method_calls用法及代碼示例
- Python unittest.mock.Mock.call_args_list用法及代碼示例
- 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.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.__class__。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。