[issue28318] Python unittest.mock.mock_calls stores references to arguments instead of their values

2016-10-04 Thread Michael Foord
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/

[issue28318] Python unittest.mock.mock_calls stores references to arguments instead of their values

2016-10-03 Thread Vedran Čačić
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

[issue28318] Python unittest.mock.mock_calls stores references to arguments instead of their values

2016-10-03 Thread Guillaume Chorn
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

[issue28318] Python unittest.mock.mock_calls stores references to arguments instead of their values

2016-09-30 Thread R. David Murray
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

[issue28318] Python unittest.mock.mock_calls stores references to arguments instead of their values

2016-09-30 Thread Guillaume Chorn
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,