[New-bugs-announce] [issue32632] Mock does not create deepcopy of mutable args
Sergey
report at bugs.python.org
Tue Jan 23 02:24:45 EST 2018
New submission from Sergey <sergejyit at gmail.com>:
MagicMock allows to check parameters of calls by using "assert_has_calls". However it fails if argument has a mutable type and was changed in-place before the second call.
The example is provided in attached file.
In "func1" value in "data" changes for each iteration and as result:
call_args_list contains two same calls.
In "func2" variable "data" generates by function "get_dict" and in this case call_args_list contains correct values.
Obviously it happens because class _Call (https://github.com/python/cpython/blob/3.5/Lib/unittest/mock.py#L1929) does not create a deepcopy of call args/kwargs.
Will it be correct to add deep_copy logic in mock.py ? or may be it's wrong to use logic like in "func1"?
I see only one disadvantage of using deepcopy: it will become slower.
----------
components: Tests
files: test.py
messages: 310476
nosy: michael.foord, skraynev
priority: normal
severity: normal
status: open
title: Mock does not create deepcopy of mutable args
versions: Python 3.5
Added file: https://bugs.python.org/file47401/test.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32632>
_______________________________________
More information about the New-bugs-announce
mailing list