[issue38346] Wrong behavior when using `assert_called_with` with mutable object
Jim Jeon added the comment: Thank you all for the kind answers. I didn't know copying could cause so many problems. @veky Thank you for the example. But it seems that the example will actually raise and I think it should. I am talking f.assert_called_with(b) when `b` has same values of `a` before it is mutated. I thought the function's purpose is to check values of the exact moment the function is called. @xtreak Thanks for the related issue. I didn't consider `identity comparison` situations. Definitely that could cause problems. @mariocj89 > copy does not fully capture "the value of the object when it was passed" for > custom types. Thank you for the kind answer, it was really helpful to me. Now I understand why copying is so dangerous. -- ___ Python tracker <https://bugs.python.org/issue38346> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38346] Wrong behavior when using `assert_called_with` with mutable object
New submission from Jim Jeon : When `assert_called_with` is used with mutable object, test fails if the object has changed. I think this is not what it meant to do. https://docs.python.org/dev/library/unittest.mock-examples.html#coping-with-mutable-arguments The same situation is explained in this document. But I don't understand why they did not fix and just are proposing some solutions to the users. -- components: Tests files: Screen Shot 2019-10-02 at 5.22.05 PM.png messages: 353727 nosy: Jim Jeon priority: normal severity: normal status: open title: Wrong behavior when using `assert_called_with` with mutable object type: enhancement versions: Python 3.7 Added file: https://bugs.python.org/file48638/Screen Shot 2019-10-02 at 5.22.05 PM.png ___ Python tracker <https://bugs.python.org/issue38346> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com