Bugfix (config): enable "spack test" when in an active environment (#15618)
For any Spack test using Spack's YAML configuration, avoid using real Spack configuration that has been cached by other tests and Spack startup logic. Previously this was only done for tests using 'mutable_config' (i.e. those which expected to *change* the configuration of Spack), but in fact all tests that read Spack config should use it. This was an issue when running tests within an environment, because compiler configuration ends up being queried earlier, and the user's real config "leaks" into the cache. Outside an environment, the cache is never set until tests touch it, so we weren't seeing this issue.
This commit is contained in:
parent
d3c1a4c94b
commit
54a6c25da6
@ -301,8 +301,17 @@ def use_configuration(config):
|
||||
"""Context manager to swap out the global Spack configuration."""
|
||||
saved = spack.config.config
|
||||
spack.config.config = config
|
||||
|
||||
# Avoid using real spack configuration that has been cached by other
|
||||
# tests, and avoid polluting the cache with spack test configuration
|
||||
# (including modified configuration)
|
||||
saved_compiler_cache = spack.compilers._cache_config_file
|
||||
spack.compilers._cache_config_file = []
|
||||
|
||||
yield
|
||||
|
||||
spack.config.config = saved
|
||||
spack.compilers._cache_config_file = saved_compiler_cache
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@ -427,10 +436,6 @@ def mutable_config(tmpdir_factory, configuration_dir, monkeypatch):
|
||||
*[spack.config.ConfigScope(name, str(mutable_dir))
|
||||
for name in ['site', 'system', 'user']])
|
||||
|
||||
# This is essential, otherwise the cache will create weird side effects
|
||||
# that will compromise subsequent tests if compilers.yaml is modified
|
||||
monkeypatch.setattr(spack.compilers, '_cache_config_file', [])
|
||||
|
||||
with use_configuration(cfg):
|
||||
yield cfg
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user