classification
Title: Unittest Mock objects do not freeze arguments they are called with
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, michael.foord, rbcollins, slacknate, xtreak
Priority: normal Keywords:

Created on 2018-04-18 15:53 by slacknate, last changed 2018-09-24 15:38 by xtreak. This issue is now closed.

Files
File name Uploaded Description Edit
mock_issue.py slacknate, 2018-04-18 15:53 Reproduces described issue, assertion error raised when it should not be.
Messages (3)
msg315456 - (view) Author: Nate Duarte (slacknate) * Date: 2018-04-18 15:53
It is possible to make a call with a Mock object, for example, where a dictionary is passed to the mock and later modified. If a call assertion is then made against the mock using the initial value/contents of the dictionary the assertion will fail.
msg319816 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-06-17 14:17
Thanks for the issue. I think this is documented here : https://docs.python.org/3/library/unittest.mock-examples.html#coping-with-mutable-arguments

Thanks
msg326253 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-24 15:38
Thanks for the details. As part of triaging I am closing this as not a bug since passing mutable  arguments to a mock object and modifying it is a documented behavior at https://docs.python.org/3/library/unittest.mock-examples.html#coping-with-mutable-arguments . Feel free to reopen this if needed.

Thanks
History
Date User Action Args
2018-09-24 15:38:28xtreaksetstatus: open -> closed
resolution: not a bug
messages: + msg326253

stage: resolved
2018-06-17 14:17:42xtreaksetnosy: + xtreak
messages: + msg319816
2018-04-21 03:30:56terry.reedysetnosy: + rbcollins, ezio.melotti, michael.foord
2018-04-18 15:53:04slacknatecreate