add_mock_module

Mocker.add_mock_module(name: str, value=None, mock_attrs: dict = None, mock_modules: dict = None)[source]

Add a fake sub-module to this Mocker instance.

Example:

>>> m = Mocker()
>>> m.add_mock_module('my_module')
>>> m.my_module.example = 'hello'
>>> print(m.my_module['example'], m.my_module.example)
hello hello
Parameters
  • name (str) – The name of the module to add.

  • value – Set the “module” to this object, instead of an instance of Mocker

  • mock_attrs (dict) – If value is None, then this can optionally contain a dictionary of attributes/items to pre-set on the Mocker instance.

  • mock_modules (dict) – If value is None, then this can optionally contain a dictionary of “modules” to pre-set on the Mocker instance.