Mocks
Replacing functions/classes in a module
from unittest.mock import patch
method_patch = patch('module.submodule.function', autospec=True)
mocked_function = method_patch.start()
method_patch.stop()
with patch('module.submodule.function', autospec=True) as mocked_function:
Replacing functions on a object
from unittest.mock import patch
method_patch = patch.object(an_object, 'object_method', autospec=True)
mocked_function = method_patch.start()
method_patch.stop()
with patch.object(an_object, 'object_method', autospec=True) as mocked_function: