From 964ea0f577cd449ea3091d140ba1eb720cf1b6d6 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 17 Mar 2015 15:40:58 +0100 Subject: [PATCH] Fix random behavior in tests --- gns3server/config.py | 21 +++++++++++++++------ tests/conftest.py | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/gns3server/config.py b/gns3server/config.py index 46f5a3ae..9bcc9038 100644 --- a/gns3server/config.py +++ b/gns3server/config.py @@ -45,9 +45,6 @@ class Config(object): # Monitor configuration files for changes self._watched_files = {} - # Override config from command line even if we modify the config file and live reload it. - self._override_config = {} - if sys.platform.startswith("win"): appname = "GNS3" @@ -90,10 +87,17 @@ class Config(object): os.path.join("/etc/xdg", appname + ".conf"), filename] - self._config = configparser.ConfigParser() - self.read_config() + self.clear() self._watch_config_file() + def clear(self): + """Restart with a clean config""" + self._config = configparser.ConfigParser() + # Override config from command line even if we modify the config file and live reload it. + self._override_config = {} + + self.read_config() + def _watch_config_file(self): asyncio.get_event_loop().call_later(1, self._check_config_file_change) @@ -185,7 +189,12 @@ class Config(object): If the section doesn't exists the section is created """ - self.set_section_config(section, {key: value}) + conf = self.get_section_config(section) + if isinstance(value, bool): + conf[key] = str(value) + else: + conf[key] = value + self.set_section_config(section, conf) @staticmethod def instance(files=None): diff --git a/tests/conftest.py b/tests/conftest.py index bb856412..378773b5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -133,8 +133,8 @@ def run_around_tests(monkeypatch): tmppath = tempfile.mkdtemp() - Config.reset() config = Config.instance() + config.clear() config.set("Server", "project_directory", tmppath) # Prevent exectuions of the VM if we forgot to mock something