Author Johannes.Baiter
Recipients Johannes.Baiter
Date 2014-03-18.14:13:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It seems that when creating a MagicMock the magic '__truediv__' method is not replaced with a mock:

>>> import mock
>>> foo = mock.MagicMock()
>>> foo / 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'MagicMock' and 'int'

The same thing works perfectly fine when using the third party module in Python 2.7, since the 2.x '__div__' seems to be mocked:

>>> import mock
>>> foo = mock.MagicMock()
>>> foo/2
<MagicMock name='mock.__div__()' id='139760595027088'>

To clarify the context, I am trying to mock a 'pathlib.Path' object in my unittest, which overloads the division operator, i.e. implements '__truediv__'.
Date User Action Args
2014-03-18 14:13:34Johannes.Baitersetrecipients: + Johannes.Baiter
2014-03-18 14:13:34Johannes.Baitersetmessageid: <>
2014-03-18 14:13:34Johannes.Baiterlinkissue20968 messages
2014-03-18 14:13:34Johannes.Baitercreate