PyDocs

Nav

Development Tools

Mock.configure_mock

  • Mock.configure_mock(**kwargs)
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': KeyError}
>>> mock.configure_mock(**attrs)
1 Example
>>> mock = Mock()
>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
>>> mock.configure_mock(**attrs)
>>> mock.method()
3
>>> mock.other()
Traceback (most recent call last):
  ...
KeyError
from the Python docs
See Also
No see-alsos for unittest.mock/Mock.configure_mock
0 Notes
No notes for Mock.configure_mock