MCPcopy Index your code
hub / github.com/python/cpython / configure_mock

Method configure_mock

Lib/unittest/mock.py:670–689  ·  view source on GitHub ↗

Set attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyE

(self, /, **kwargs)

Source from the content-addressed store, hash-verified

668
669
670 def configure_mock(self, /, **kwargs):
671 """Set attributes on the mock through keyword arguments.
672
673 Attributes plus return values and side effects can be set on child
674 mocks using standard dot notation and unpacking a dictionary in the
675 method call:
676
677 >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
678 >>> mock.configure_mock(**attrs)"""
679 for arg, val in sorted(kwargs.items(),
680 # we sort on the number of dots so that
681 # attributes are set before we set attributes on
682 # attributes
683 key=lambda entry: entry[0].count('.')):
684 args = arg.split('.')
685 final = args.pop()
686 obj = self
687 for entry in args:
688 obj = getattr(obj, entry)
689 setattr(obj, final, val)
690
691
692 def __getattr__(self, name):

Callers 5

__init__Method · 0.95
create_autospecFunction · 0.80
test_configure_mockMethod · 0.80

Calls 4

itemsMethod · 0.45
countMethod · 0.45
splitMethod · 0.45
popMethod · 0.45