For starters, MagicMock is a subclass of Mock .
class MagicMock(MagicMixin, Mock)
As a result, MagicMock provides everything that Mock provides, and much more. Instead of thinking that Mock is a stripped-down version of MagicMock, think of MagicMock as an extended version of Mock. This should answer your questions about why Mock exists and what Mock gives in addition to MagicMock.
Secondly, MagicMock provides standard implementations of many / the most magical methods, while Mock does not. See here for more information on the magic methods provided.
Some examples of magic methods provided:
>>> int(Mock()) TypeError: int() argument must be a string or a number, not 'Mock' >>> int(MagicMock()) 1 >>> len(Mock()) TypeError: object of type 'Mock' has no len() >>> len(MagicMock()) 0
And those that may not be so intuitive (at least not intuitive for me):
>>> with MagicMock(): ... print 'hello world' ... hello world >>> MagicMock()[1] <MagicMock name='mock.__getitem__()' id='4385349968'>
You can “see” the methods added to MagicMock, as these methods are called for the first time:
>>> magic1 = MagicMock() >>> dir(magic1) ['assert_any_call', 'assert_called_once_with', ...] >>> int(magic1) 1 >>> dir(magic1) ['__int__', 'assert_any_call', 'assert_called_once_with', ...] >>> len(magic1) 0 >>> dir(magic1) ['__int__', '__len__', 'assert_any_call', 'assert_called_once_with', ...]
So why not use MagicMock all the time?
Question to you: are you ok with default magic method implementations? For example, is this normal for mocked_object[1] so that it doesn't fail? Are you okay with any unforeseen consequences due to the fact that the implementation of the magic method already exists?
If the answer to these questions is yes, then go and use MagicMock. Otherwise, stick with the Mock.