This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Johannes.Baiter
Recipients Johannes.Baiter
Date 2014-03-18.14:13:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1395152014.45.0.112877741.issue20968@psf.upfronthosting.co.za>
In-reply-to
Content
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__'.
History
Date User Action Args
2014-03-18 14:13:34Johannes.Baitersetrecipients: + Johannes.Baiter
2014-03-18 14:13:34Johannes.Baitersetmessageid: <1395152014.45.0.112877741.issue20968@psf.upfronthosting.co.za>
2014-03-18 14:13:34Johannes.Baiterlinkissue20968 messages
2014-03-18 14:13:34Johannes.Baitercreate