PyDocs

Nav

Development Tools

MagicMock

  • MagicMock(*args, **kw)
MagicMock is a subclass of Mock with default implementations
of most of the magic methods. You can use MagicMock without having to
configure the magic methods yourself.

If you use the `spec` or `spec_set` arguments then *only* magic
methods that exist in the spec will be created.

Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
1 Example
>>> from unittest.mock import MagicMock
>>> thing = ProductionClass()
>>> thing.method = MagicMock(return_value=3)
>>> thing.method(3, 4, 5, key='value')
3
>>> thing.method.assert_called_with(3, 4, 5, key='value')
from the Python docs
See Also
No see-alsos for unittest.mock/MagicMock
0 Notes
No notes for MagicMock