PyDocs

Development Tools

unittest.mock

unittest.mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
Symbols in unittest.mock

a

AsyncMock
Enhance :class:`Mock` with features allowing to mock an async function.

c

call
call() is a helper object for making simpler assertions, for comparing with call_args, call_args_list, mock_calls and method_calls.
create_autospec
Create a mock object using another object as a spec.

d

DEFAULT
The DEFAULT object is a pre-created sentinel (actually sentinel.DEFAULT).

m

MagicMock
MagicMock is a subclass of Mock with default implementations of most of the magic methods.
Mock
Create a new `Mock` object.
mock_open
A helper function to create a mock to replace the use of `open`.

n

NonCallableMagicMock
A version of `MagicMock` that isn't callable.
NonCallableMock
A non-callable version of `Mock`

p

patch
`patch` acts as a function decorator, class decorator or a context manager.
PropertyMock
A mock intended to be used as a property, or other descriptor, on a class.

s

seal
Disable the automatic generation of child mocks.
sentinel
The sentinel object provides a convenient way of providing unique objects for your tests.

t

ThreadingMock
A mock that can be used to wait until on calls happening in a different thread.