Skip to content

Commit

Permalink
replace tempdir with tmp_path fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Oct 25, 2022
1 parent ec43003 commit 2101279
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions qcodes/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def disable_telemetry():


@pytest.fixture(scope="function")
def default_config():
def default_config(tmp_path):
"""
Fixture to temporarily establish default config settings.
This is achieved by overwriting the config paths of the user-,
Expand All @@ -68,32 +68,30 @@ def default_config():
cwd_file_name = Config.cwd_file_name
schema_cwd_file_name = Config.schema_cwd_file_name

Config.home_file_name = ""
with tempfile.TemporaryDirectory() as tmpdirname:
file_name = os.path.join(tmpdirname, "user_config.json")
file_name_schema = os.path.join(tmpdirname, "user_config_schema.json")

Config.home_file_name = file_name
Config.schema_home_file_name = file_name_schema
Config.env_file_name = ""
Config.schema_env_file_name = ""
Config.cwd_file_name = ""
Config.schema_cwd_file_name = ""

default_config_obj: DotDict | None = copy.deepcopy(qc.config.current_config)
qc.config = Config()

try:
yield
finally:
Config.home_file_name = home_file_name
Config.schema_home_file_name = schema_home_file_name
Config.env_file_name = env_file_name
Config.schema_env_file_name = schema_env_file_name
Config.cwd_file_name = cwd_file_name
Config.schema_cwd_file_name = schema_cwd_file_name

qc.config.current_config = default_config_obj
file_name = str(tmp_path / "user_config.json")
file_name_schema = str(tmp_path / "user_config_schema.json")

Config.home_file_name = file_name
Config.schema_home_file_name = file_name_schema
Config.env_file_name = ""
Config.schema_env_file_name = ""
Config.cwd_file_name = ""
Config.schema_cwd_file_name = ""

default_config_obj: DotDict | None = copy.deepcopy(qc.config.current_config)
qc.config = Config()

try:
yield
finally:
Config.home_file_name = home_file_name
Config.schema_home_file_name = schema_home_file_name
Config.env_file_name = env_file_name
Config.schema_env_file_name = schema_env_file_name
Config.cwd_file_name = cwd_file_name
Config.schema_cwd_file_name = schema_cwd_file_name

qc.config.current_config = default_config_obj


@pytest.fixture(scope="function")
Expand Down

0 comments on commit 2101279

Please sign in to comment.