mocksafe.mock_module

mocksafe.mock_module(module: M, name: str | None = None) M

Creates a mocked version of the given module.

Parameters:
  • module (M) – module to be mocked of generic ModuleType M

  • name (str, optional) – optional custom name to help identify the mock object in str representations

Returns:

a mock object but typed with the generic ModuleType M

Return type:

M

Example:
>>> import random
>>> mock_random = mock_module(random)
>>> mock_random  
SafeMock(<class 'MockSpec(module=random)'>,
         <module 'random' from '.../random.py'>)

To stub a mocked function on the module see:

mocksafe.when()

To assert calls made to a mocked function see:

mocksafe.that()

To retrieve calls that were made to a mocked function see:

mocksafe.spy()