[issue33667] Mock calls on mutable objects

2018-05-28 Thread R. David Murray


Change by R. David Murray :


--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Python unittest.mock.mock_calls stores references to arguments 
instead of their values

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33667] Mock calls on mutable objects

2018-05-28 Thread Pawel


Pawel  added the comment:

Ok, fair enough. Thank You for explanation. I was just surprised with this 
behaviour.
On the other hand, I don't like mutable objects and I'm trying to avoid them.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33667] Mock calls on mutable objects

2018-05-28 Thread Lady Red

Lady Red  added the comment:

To have the behavior that you are expecting, I believe the mock would have to 
store a deep copy of every mutable object that is passed in to any of it's 
calls, in case that object later mutates. 

That would really expand the memory and time footprint of working with a Mock 
object.  The mock object would grow with every call to. (This is already true, 
as it's adding to it's mock_calls list... but it would grow much more. )

I'm also not sure about the safety of trying to deepcopy all objects passed in. 

I think that in addition to the safety and memory/performance issues that I've 
highlighted, deepcopying all objects would lead to it's own unintuitive 
behaviors.  Objects you get back from mock_call wouldn't be the objects that it 
was actually called with, they would be copies. 

I am attaching a file that illustrates this last point.

--
nosy: +mcsc...@gmail.com
Added file: https://bugs.python.org/file47622/unintuitive_side_effect.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33667] Mock calls on mutable objects

2018-05-28 Thread Pawel

New submission from Pawel :

When method of mocked object is called multiple times with mutable object as 
parameter and attribute of this object has been updated between calls, 
mock_calls is only aware of the last value. I think it unexpected behaviour, 
that mock doesn't track value changes.
I've attached example code

--
components: Tests
files: test.py
messages: 317849
nosy: pawelj
priority: normal
severity: normal
status: open
title: Mock calls on mutable objects
type: behavior
versions: Python 3.5, Python 3.6
Added file: https://bugs.python.org/file47618/test.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com