diff --git a/pytest_client_tools/insights_client.py b/pytest_client_tools/insights_client.py index 6e60160..977204d 100644 --- a/pytest_client_tools/insights_client.py +++ b/pytest_client_tools/insights_client.py @@ -128,6 +128,14 @@ def __getattr__(self, name): except configparser.NoOptionError: raise KeyError(name) + def __setattr__(self, name, value): + if name in ( + self._KEYS_BOOL | self._KEYS_INT | self._KEYS_FLOAT | self._KEYS_STRING + ): + self._config.set("insights-client", name, str(value)) + return + super().__setattr__(name, value) + class InsightsClient: def __init__(self): diff --git a/tests/test_insights_client.py b/tests/test_insights_client.py index 5f7e95e..1481631 100644 --- a/tests/test_insights_client.py +++ b/tests/test_insights_client.py @@ -61,6 +61,30 @@ def test_config_existing_keys(tmp_path): assert isinstance(conf.http_timeout, float) +def test_config_set_keys(tmp_path): + conf_file = tmp_path / "file.conf" + conf_file.write_text( + """[insights-client] +auto_config=True +authmethod=CERT +cmd_timeout=120 +http_timeout=120 + """ + ) + conf = InsightsClientConfig(conf_file) + # existing key + conf.cmd_timeout = 60 + assert conf.cmd_timeout == 60 + # missing but known key + with pytest.raises(KeyError): + assert conf.loglevel == "DEBUG" + conf.loglevel = "DEBUG" + assert conf.loglevel == "DEBUG" + # unknown key; setting will set a class attribute, not a config value + conf.unknown = "see" + assert conf.unknown == "see" + + def test_config_reload(tmp_path): conf_file = tmp_path / "file.conf" conf_file.write_text(