[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 reliable; i.e. make it clear that we're storing a 
reference to the arguments and not just the values. If it's not a bug, it's 
certainly a limitation that deserves as much mention as possible.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28318>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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, this results in the undesirable behavior below:

```python
import mock

arg = ['one']

test_function(arg)

# passes
test_function.assert_has_calls([mock.call(['one'])])

arg += ['two']

test_function(arg)

# fails, even though we just verified the first call above!
test_function.assert_has_calls([
mock.call(['one']),
mock.call(['one','two'])
])

# passes, even though we didn't make the exact same call twice!
test_function.assert_has_calls([
mock.call(['one', 'two']),
mock.call(['one', 'two'])
])
```

--
components: Tests
messages: 277764
nosy: Guillaume Chorn
priority: normal
severity: normal
status: open
title: Python unittest.mock.mock_calls stores references to arguments instead 
of their values
type: behavior
versions: Python 3.4

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28318>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com