Michael Foord added the comment:
This is a deliberate design decision of mock. Storing references works better
for the more general case, with the trade-off being that it doesn't work so
well for mutable arguments.
See the note in the docs with a workaround:
https://docs.python.org/3/library/
Vedran Čačić added the comment:
> # passes, even though we didn't make the exact same call twice!
Weird. It looks like a matter of perspective, but to me it surely _does_ seem
like you _did_ make the exact same call twice.
> test_function(arg)
> test_function(arg)
Neither test_function nor ar
Guillaume Chorn added the comment:
If it's true that our ability to accurately deep-copy mutable args makes fixing
this behavior impossible, we should at the very least update the official
unittest.mock documentation to warn users that testing for mock calls with
mutable arguments is not relia
R. David Murray added the comment:
This is pretty much just the way python works. The only alternative would be
for mock to try to do a deepcopy, which won't always work, so it is probably
better not to do it at all.
--
nosy: +michael.foord, r.david.murray, rbcollins
New submission from Guillaume Chorn:
In the unittest.mock library, when a Mock object stores the calls made on it in
its `mock_calls` attribute, it appears to store references to the call
arguments instead of the actual values of the call arguments. In cases where
call args are mutable types,