import contextlib


def configure_caching(config_with_profile_factory):
    """
    Fixture to set the caching configuration in the test profile to
    a specific dictionary. This is done by creating a temporary
    caching configuration file.
    """
    config = config_with_profile_factory()

    @contextlib.contextmanager
    def inner(config_dict):
        for key, value in config_dict.items():
            config.set_option(f'caching.{key}', value)
        yield
        # reset the configuration
        for key in config_dict.keys():
            config.unset_option(f'caching.{key}')

    return inner