Message404847
This issue also came up with MagicMock on stackoverflow: https://stackoverflow.com/questions/23257227/python-mock-method-call-arguments-display-the-last-state-of-a-list/23264042
Dave: glad this helped to clear it up. For the record, the arguments in Python are passed by object reference, which is not the same as by reference or by value; - it means that mutable objects can be mutated by receiving func and immutable objs cannot be mutated. In your case it was a mutable object, you mutated it, but compared it to value that it had before mutation.
I've thought if this should be cleared up in the docs, but I think in most cases it will be fairly obvious to see what happened because the tested value will differ from expected exactly in the way that the function modifies it. But if more people run into this confusion, we should consider adding a note to MagicMock, call_args, and call_args_list (and maybe some other mock attrs). |
|
Date |
User |
Action |
Args |
2021-10-23 00:22:46 | andrei.avk | set | recipients:
+ andrei.avk, kj, dmcnulla |
2021-10-23 00:22:46 | andrei.avk | set | messageid: <1634948566.88.0.10753570936.issue45305@roundup.psfhosted.org> |
2021-10-23 00:22:46 | andrei.avk | link | issue45305 messages |
2021-10-23 00:22:46 | andrei.avk | create | |
|