@contextlib.contextmanager
def changed_config(key, value):
 _original_config = config.copy()
 config[key] = value
 try:
  (yield)
 finally:
  config.clear()
  config.update(_original_config)

@ contextlib . contextmanager def changed_config ( key , value ) : _original_config = config . copy ( ) config [ key ] = value try : ( yield ) finally : config . clear ( ) config . update ( _original_config )
context manager for temporarily changing a config value .