def test_magic_methods_mock_calls(self): for Klass in Mock, MagicMock: m = Klass() m.__int__ = Mock(return_value=3) m.__float__ = MagicMock(return_value=3.0) int(m) float(m) self.assertEqual(m.mock_calls, [call.__int__(), call.__float__()]) self.assertEqual(m.method_calls, [])
def test_mock_and_method_calls(): mock = MagicMock() mock() mock.attr() mock.attr.method() int(mock) int(mock.attr) assert mock.mock_calls == [ call(), call.attr(), call.attr.method(), call.__int__(), call.attr.__int__() ] assert mock.method_calls == [ # no calls to mock object itself, and to magic methods call.attr(), call.attr.method() ]
def test_mock_and_method_calls(): mock = MagicMock() mock() mock.attr() mock.attr.method() int(mock) int(mock.attr) assert mock.mock_calls == [ call(), call.attr(), call.attr.method(), call.__int__(), call.attr.__int__() ] assert mock.method_calls == [ # no calls to mock object itself, and to magic methods call.attr(), call.attr.method() ]