summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2022-01-17 11:04:54 -0800
committerGreg Becker <becker33@llnl.gov>2022-02-16 10:17:18 -0800
commitf155de7462d7863fa9b89e4303f37c0edafa8125 (patch)
tree021ef4043bb748204934ee91d57be349a13f30ae /lib
parent800ed16e7a3b95b15f831a26b92c753e43934b65 (diff)
downloadspack-f155de7462d7863fa9b89e4303f37c0edafa8125.tar.gz
spack-f155de7462d7863fa9b89e4303f37c0edafa8125.tar.bz2
spack-f155de7462d7863fa9b89e4303f37c0edafa8125.tar.xz
spack-f155de7462d7863fa9b89e4303f37c0edafa8125.zip
tests: consolidate mock scope creation logic in `conftest.py`
Config scopes were different for `config` and `mutable_config`, and `mutable_config` did not have a command line scope. - [x] Fix by consolidating the creation logic for the two fixtures.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/bootstrap.py10
-rw-r--r--lib/spack/spack/test/conftest.py30
2 files changed, 18 insertions, 22 deletions
diff --git a/lib/spack/spack/test/bootstrap.py b/lib/spack/spack/test/bootstrap.py
index 719b1a6a5f..8b72a98ad3 100644
--- a/lib/spack/spack/test/bootstrap.py
+++ b/lib/spack/spack/test/bootstrap.py
@@ -103,16 +103,8 @@ def test_bootstrap_search_for_compilers_with_environment_active(
@pytest.mark.regression('26189')
def test_config_yaml_is_preserved_during_bootstrap(mutable_config):
- # Mock the command line scope
expected_dir = '/tmp/test'
- internal_scope = spack.config.InternalConfigScope(
- name='command_line', data={
- 'config': {
- 'test_stage': expected_dir
- }
- }
- )
- spack.config.config.push_scope(internal_scope)
+ spack.config.set("config:test_stage", expected_dir, scope="command_line")
assert spack.config.get('config:test_stage') == expected_dir
with spack.bootstrap.ensure_bootstrap_configuration():
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index cedc9d4f22..36a45bb637 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -612,19 +612,23 @@ def configuration_dir(tmpdir_factory, linux_os):
shutil.rmtree(str(tmpdir))
+def _create_mock_configuration_scopes(configuration_dir):
+ """Create the configuration scopes used in `config` and `mutable_config`."""
+ scopes = [
+ spack.config.InternalConfigScope('_builtin', spack.config.config_defaults),
+ ]
+ scopes += [
+ spack.config.ConfigScope(name, str(configuration_dir.join(name)))
+ for name in ['site', 'system', 'user']
+ ]
+ scopes += [spack.config.InternalConfigScope('command_line')]
+ return scopes
+
+
@pytest.fixture(scope='session')
def mock_configuration_scopes(configuration_dir):
"""Create a persistent Configuration object from the configuration_dir."""
- defaults = spack.config.InternalConfigScope(
- '_builtin', spack.config.config_defaults
- )
- test_scopes = [defaults]
- test_scopes += [
- spack.config.ConfigScope(name, str(configuration_dir.join(name)))
- for name in ['site', 'system', 'user']]
- test_scopes.append(spack.config.InternalConfigScope('command_line'))
-
- yield test_scopes
+ yield _create_mock_configuration_scopes(configuration_dir)
@pytest.fixture(scope='function')
@@ -640,9 +644,7 @@ def mutable_config(tmpdir_factory, configuration_dir):
mutable_dir = tmpdir_factory.mktemp('mutable_config').join('tmp')
configuration_dir.copy(mutable_dir)
- scopes = [spack.config.ConfigScope(name, str(mutable_dir.join(name)))
- for name in ['site', 'system', 'user']]
-
+ scopes = _create_mock_configuration_scopes(mutable_dir)
with spack.config.use_configuration(*scopes) as cfg:
yield cfg
@@ -662,6 +664,8 @@ def mutable_empty_config(tmpdir_factory, configuration_dir):
def no_compilers_yaml(mutable_config):
"""Creates a temporary configuration without compilers.yaml"""
for scope, local_config in mutable_config.scopes.items():
+ if not local_config.path: # skip internal scopes
+ continue
compilers_yaml = os.path.join(local_config.path, 'compilers.yaml')
if os.path.exists(compilers_yaml):
os.remove(compilers_yaml)