From 54a6c25da637418f568b3419bd1e467ffdd0870b Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 23 Mar 2020 15:15:36 -0700 Subject: 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. --- lib/spack/spack/test/conftest.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3-60-g2f50