python-configuration icon indicating copy to clipboard operation
python-configuration copied to clipboard

Patching ConfigurationSet

Open mcaulifn opened this issue 3 years ago • 1 comments

What is the proper way to patch a config using something like @patch.dict? In the example below, I would like to insert a custom url value in the test.

Sample config:

configs.py

from config import ConfigurationSet, config_from_env, config_from_yaml
CONFIG = ConfigurationSet(
    config_from_yaml(f'{BASE_PATH}/{FLAVOR}.yaml', read_from_file=True),
    config_from_yaml(f'{BASE_PATH}/default.yaml', read_from_file=True),
)

client.py

import requests
from configs import CONFIG

def send_get():
    response = request.get(CONFIG['url'])

mcaulifn avatar Mar 03 '22 14:03 mcaulifn

For a ConfigurationSet, you can patch the _configs dictionary and add another Configuration object with the url setting you need.

tr11 avatar Mar 03 '22 17:03 tr11