Skip to the content.

The Mock Object

Defining a Mock Object

Take a close look at this code.

Try to predict what will happen.

from unittest.mock import Mock
mock = Mock()
mock.return_value = 3
mock()
mock.assert_called_once_with()
mock()
mock.assert_called_once_with()

Let’s read this code together now:

Now you’ve just learned to assert mocked method calls

Mapping method to be mocked by Mock

In development

Be patient

Mapping exceptions

In development

Be patient

More on side-effect

In development

Be patient

Go to