Skip to content

mock.Mock does not record the value of arguments, but record reference of them #94348

Closed as not planned
@hoon0422

Description

@hoon0422

Bug report

When using mock.call to check the calls of mock.Mock instance with dictionary arguments, there seems to be a bug:

from mock import Mock, call

mock = Mock()
arg = {}

mock(arg)
arg['el'] = 1

mock.assert_has_calls({})  # This raises assertion exception

"""
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/python37/lib/python3.7/site-packages/mock/mock.py", line 969, in assert_has_calls
    ), cause)
  File "<string>", line 3, in raise_from
AssertionError: Calls not found.
Expected: [call({})]
Actual: [call({'el': 1})]
"""

I thought the last assertion should not create an exception

Your environment

  • CPython versions, Operating system tested on: 3.9.7 (mac os 12.4), 3.7.13 (ubuntu 20.04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions