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 andrei.avk
Recipients andrei.avk, dmcnulla, kj
Date 2021-10-23.00:22:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634948566.88.0.10753570936.issue45305@roundup.psfhosted.org>
In-reply-to
Content
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).
History
Date User Action Args
2021-10-23 00:22:46andrei.avksetrecipients: + andrei.avk, kj, dmcnulla
2021-10-23 00:22:46andrei.avksetmessageid: <1634948566.88.0.10753570936.issue45305@roundup.psfhosted.org>
2021-10-23 00:22:46andrei.avklinkissue45305 messages
2021-10-23 00:22:46andrei.avkcreate