Message213964
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:34 | Johannes.Baiter | set | recipients:
+ Johannes.Baiter |
2014-03-18 14:13:34 | Johannes.Baiter | set | messageid: <1395152014.45.0.112877741.issue20968@psf.upfronthosting.co.za> |
2014-03-18 14:13:34 | Johannes.Baiter | link | issue20968 messages |
2014-03-18 14:13:34 | Johannes.Baiter | create | |
|