Message325571
It is documented, that divmod() returns a pair. It is usually used with tuple unpacking:
x, y = divmod(a, b)
But this doesn't work when one of arguments is a MagicMock.
>>> from unittest.mock import *
>>> x, y = divmod(MagicMock(), 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 2, got 0)
I expect that tuple unpacking will work with the result of MagicMock.__divmod__(). There possible following options:
1. Return some constant value, e.g. (1, 0).
2. Return a pair of new MagicMock instances.
3. Define __divmod__ in terms of __floordiv__ and __mod__. This will automatically return a pair of MagicMock instances by default, but setting return values for __floordiv__ and __mod__ will affect the result of __divmod__.
What is more preferable? |
|
Date |
User |
Action |
Args |
2018-09-17 19:45:58 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, michael.foord |
2018-09-17 19:45:58 | serhiy.storchaka | set | messageid: <1537213558.4.0.956365154283.issue34716@psf.upfronthosting.co.za> |
2018-09-17 19:45:58 | serhiy.storchaka | link | issue34716 messages |
2018-09-17 19:45:58 | serhiy.storchaka | create | |
|