diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 3bf64451471..79692a9dc5c 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -90,6 +90,15 @@ def env_root_path(): ) +def check_disallowed_env_config_mods(scopes): + for scope in scopes: + with spack.config.override(scope): + if spack.config.get("config:environments_root"): + raise SpackEnvironmentError("Need a good message") + else: + spack.config.print_section("config") + return scopes + def default_manifest_yaml(): """default spack.yaml file to put in new environments""" return """\ @@ -1039,17 +1048,9 @@ def env_file_config_scope(self): [spack.config.first_existing(self.raw_yaml, spack.schema.env.keys)], ) - def _check_disallowed_env_config_mods(scopes): - for scope in scopes: - with spack.config.override(scope): - if spack.config.get("config:environments_root"): - raise SpackEnvironmentError("Need a good message") - else: - spack.config.print_section("config") - def config_scopes(self): """A list of all configuration scopes for this environment.""" - return _check_disallowed_env_config_mods( + return check_disallowed_env_config_mods( self.included_config_scopes() + [self.env_file_config_scope()] ) diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index 41bac1ad72f..1954a93e0f1 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -1478,6 +1478,11 @@ def test_environment_cant_modify_environments_root(tmpdir): """ ) with tmpdir.as_cwd(): - env("create", "-d", tmpdir.strpath) with pytest.raises(ev.SpackEnvironmentError): + # Why does this raise? + e = ev.Environment(tmpdir.strpath) + ev.activate(e) + with pytest.raises(ev.SpackEnvironmentError): + # When this does not? + env("create", "-d", tmpdir.strpath) env("activate", "-d", tmpdir.strpath)