libb.patch_library_config

patch_library_config(library_name, config_name='config', **config_overrides)[source]

Patch a library’s config module directly in sys.modules.

Finds and patches the library’s config module before the library imports it. Works regardless of import order by patching the config module directly.

Parameters:
  • library_name (str) – Name of the library whose config should be patched.

  • config_name (str) – Name of the config module (default: ‘config’).

  • config_overrides (Any) – Configuration values to set with keys as dotted paths.

Return type:

None

Example:

>>> import sys
>>> from libb import create_mock_module
>>> Setting.unlock()
>>> api = Setting()
>>> api.key = 'oldkey'
>>> Setting.lock()
>>> create_mock_module('mylib', {})  # parent module
>>> create_mock_module('mylib.config', {'api': api})
>>> patch_library_config('mylib', api_key='newkey')
>>> sys.modules['mylib.config'].api.key
'newkey'