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)
| 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): |