summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2020-03-23 15:15:36 -0700
committerGitHub <noreply@github.com>2020-03-23 15:15:36 -0700
commit54a6c25da637418f568b3419bd1e467ffdd0870b (patch)
treed8463f588f5659ee74688e2f8484935fe5d891e4 /lib
parentd3c1a4c94bbfe95aacbc473dcc24183b04cdb29f (diff)
downloadspack-54a6c25da637418f568b3419bd1e467ffdd0870b.tar.gz
spack-54a6c25da637418f568b3419bd1e467ffdd0870b.tar.bz2
spack-54a6c25da637418f568b3419bd1e467ffdd0870b.tar.xz
spack-54a6c25da637418f568b3419bd1e467ffdd0870b.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/conftest.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index 6703742142..a186463907 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -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