diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2018-10-26 17:33:22 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2018-11-09 00:31:24 -0800 |
commit | 40af955b94d10939d743b373363ef65b5ee417bc (patch) | |
tree | 64f42091ec7deb3cd4eda46b3dcbeded02f6fbf2 | |
parent | c27b78ee369bf26ed27b35c6f19a9f546218f8ec (diff) | |
download | spack-40af955b94d10939d743b373363ef65b5ee417bc.tar.gz spack-40af955b94d10939d743b373363ef65b5ee417bc.tar.bz2 spack-40af955b94d10939d743b373363ef65b5ee417bc.tar.xz spack-40af955b94d10939d743b373363ef65b5ee417bc.zip |
env: prevent any active environments from interfering with tests
- ensure that `SPACK_ENV` is unset before tests
- ensure that `spack.environment.active` is deactivated if set
-rw-r--r-- | lib/spack/spack/test/conftest.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index cbdc79cbba..a13444a1a8 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -23,6 +23,7 @@ import spack.config import spack.caches import spack.database import spack.directory_layout +import spack.environment as ev import spack.paths import spack.platforms.test import spack.repo @@ -37,6 +38,27 @@ from spack.spec import Spec from spack.version import Version +# +# Disable any activate Spack environment BEFORE all tests +# +@pytest.fixture(scope='session', autouse=True) +def clean_user_environment(): + env_var = ev.spack_env_var in os.environ + active = ev.active + + if env_var: + spack_env_value = os.environ.pop(ev.spack_env_var) + if active: + ev.deactivate() + + yield + + if env_var: + os.environ[ev.spack_env_var] = spack_env_value + if active: + ev.activate(active) + + # Hooks to add command line options or set other custom behaviors. # They must be placed here to be found by pytest. See: # |