summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>2019-06-17 02:38:34 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2019-06-17 11:38:34 +0200
commit6e067a05c700b59ec379d2e573a2874d6cb4d935 (patch)
treee015a367cdfd27932089a8f18aa4d1f19599f0e7
parenta551e4329ef97f3215591c768f49fd7fc04fdc90 (diff)
downloadspack-6e067a05c700b59ec379d2e573a2874d6cb4d935.tar.gz
spack-6e067a05c700b59ec379d2e573a2874d6cb4d935.tar.bz2
spack-6e067a05c700b59ec379d2e573a2874d6cb4d935.tar.xz
spack-6e067a05c700b59ec379d2e573a2874d6cb4d935.zip
bugfix: use config fixture for stage tests (#11701)
Some tests introduced in #11528 temporarily set the user's `config:build_stage`, which affected (or created) a config.yaml file in the user's `$HOME/.spack` directory that could leave entries behind if the tests fail. This change ensures only temporary configuration files are used/affected by these tests.
-rw-r--r--lib/spack/spack/stage.py2
-rw-r--r--lib/spack/spack/test/stage.py27
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index 9e2c8865e4..379104a51f 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -73,7 +73,7 @@ def get_tmp_root():
path = _first_accessible_path(candidates)
if not path:
- raise StageError("No accessible stage paths in %s", candidates)
+ raise StageError("No accessible stage paths in:", candidates)
# Return None to indicate we're using a local staging area.
if path == canonicalize_path(spack.paths.stage_path):
diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py
index 6b5e698dc3..74f3c9b4fa 100644
--- a/lib/spack/spack/test/stage.py
+++ b/lib/spack/spack/test/stage.py
@@ -178,6 +178,16 @@ def get_stage_path(stage, stage_name):
@pytest.fixture
+def no_path_for_stage(monkeypatch):
+ """Ensure there is no accessible path for staging."""
+ def _no_stage_path(paths):
+ return None
+
+ monkeypatch.setattr(spack.stage, '_first_accessible_path', _no_stage_path)
+ yield
+
+
+@pytest.fixture
def no_tmp_root_stage(monkeypatch):
"""
Disable use of a temporary root for staging.
@@ -191,7 +201,7 @@ def no_tmp_root_stage(monkeypatch):
@pytest.fixture
-def non_user_path_for_stage():
+def non_user_path_for_stage(config):
"""
Use a non-user path for staging.
@@ -206,7 +216,7 @@ def non_user_path_for_stage():
@pytest.fixture
-def stage_path_for_stage():
+def stage_path_for_stage(config):
"""
Use the basic stage_path for staging.
@@ -221,7 +231,7 @@ def stage_path_for_stage():
@pytest.fixture
-def tmp_path_for_stage(tmpdir):
+def tmp_path_for_stage(tmpdir, config):
"""
Use a built-in, temporary, test directory for staging.
@@ -248,7 +258,7 @@ def tmp_root_stage(monkeypatch):
@pytest.fixture
-def tmpdir_for_stage(mock_stage_archive):
+def tmpdir_for_stage(config, mock_stage_archive):
"""
Use the mock_stage_archive's temporary directory for staging.
@@ -266,7 +276,7 @@ def tmpdir_for_stage(mock_stage_archive):
@pytest.fixture
-def tmp_build_stage_dir(tmpdir):
+def tmp_build_stage_dir(tmpdir, config):
"""Establish the temporary build_stage for the mock archive."""
test_tmp_path = tmpdir.join('tmp')
@@ -671,6 +681,13 @@ class TestStage(object):
"""Ensure not using tmp root results in no path."""
assert spack.stage.get_tmp_root() is None
+ def test_get_tmp_root_no_stage_path(self, tmp_root_stage,
+ no_path_for_stage):
+ """Ensure using tmp root with no stage path raises StageError."""
+ with pytest.raises(spack.stage.StageError,
+ match="No accessible stage paths in"):
+ spack.stage.get_tmp_root()
+
def test_get_tmp_root_non_user_path(self, tmp_root_stage,
non_user_path_for_stage):
"""Ensure build_stage of tmp root with non-user path includes user."""