Skip to content

Commit 43176cb

Browse files
authored
Store default profile in aiida_profile_factory (#6893)
Ensures that the config set in fixture `aiida_profile_factory` is stored persistently on disk and not just in memory. Tests have been added that use the `aiida_config_tmp` implicitly through autouse `aiida_profile` fixture. The test checks if the default profile is set when loading the config from file. Note that `aiida_profile_factory` is intended to be used with a path argument to chose the configuration directory. By that we avoid race conditions on configuration tests due to concurrent tests. The tests did not fail before because only the default profile option was not stored persistently while the profile was, and further all CLI tests specify the profile explicitly.
1 parent edb8c7e commit 43176cb

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/aiida/tools/pytest_fixtures/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def factory(
141141
is_test_profile=True,
142142
)
143143
config.set_default_profile(profile.name)
144+
config.store()
144145

145146
def reset_storage():
146147
"""Reset the storage of the profile.

tests/tools/pytest_fixtures/test_configuration.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
"""Test the pytest fixtures."""
22

3+
from pathlib import Path
4+
5+
from aiida.manage.configuration import get_config, load_config
6+
from aiida.manage.configuration.settings import DEFAULT_CONFIG_FILE_NAME
7+
38

49
def test_aiida_config(tmp_path_factory):
510
"""Test that ``aiida_config`` fixture is loaded by default and creates a config instance in temp directory."""
6-
from aiida.manage.configuration import get_config
7-
from aiida.manage.configuration.config import Config
11+
from aiida.manage.configuration import CONFIG
12+
13+
config = get_config(create=False)
14+
assert config is CONFIG
15+
assert config.dirpath.startswith(str(tmp_path_factory.getbasetemp()))
16+
assert Path(config.dirpath, DEFAULT_CONFIG_FILE_NAME).is_file()
17+
assert config._default_profile
18+
819

9-
config = get_config()
10-
assert isinstance(config, Config)
20+
def test_aiida_config_file(tmp_path_factory):
21+
"""Test that ``aiida_config`` fixture stores the configuration in a config file in a temp directory."""
22+
# Unlike get_config, load_config always loads the configuration from a file
23+
config = load_config(create=False)
1124
assert config.dirpath.startswith(str(tmp_path_factory.getbasetemp()))
25+
assert Path(config.dirpath, DEFAULT_CONFIG_FILE_NAME).is_file()
26+
assert config._default_profile
1227

1328

1429
def test_aiida_config_tmp(aiida_config_tmp, tmp_path_factory):

0 commit comments

Comments
 (0)