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
This commit is contained in:
parent
c27b78ee36
commit
40af955b94
@ -23,6 +23,7 @@
|
|||||||
import spack.caches
|
import spack.caches
|
||||||
import spack.database
|
import spack.database
|
||||||
import spack.directory_layout
|
import spack.directory_layout
|
||||||
|
import spack.environment as ev
|
||||||
import spack.paths
|
import spack.paths
|
||||||
import spack.platforms.test
|
import spack.platforms.test
|
||||||
import spack.repo
|
import spack.repo
|
||||||
@ -37,6 +38,27 @@
|
|||||||
from spack.version import Version
|
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.
|
# Hooks to add command line options or set other custom behaviors.
|
||||||
# They must be placed here to be found by pytest. See:
|
# They must be placed here to be found by pytest. See:
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user