Skip to content

Commit

Permalink
bugfix: use config fixture for stage tests (#11701)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tldahlgren authored and tgamblin committed Jun 17, 2019
1 parent a551e43 commit 6e067a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/spack/spack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
27 changes: 22 additions & 5 deletions lib/spack/spack/test/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ def get_stage_path(stage, stage_name):
return stage.path


@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):
"""
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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')

Expand Down Expand Up @@ -671,6 +681,13 @@ def test_get_tmp_root_no_use(self, no_tmp_root_stage):
"""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."""
Expand Down

0 comments on commit 6e067a0

Please sign in to comment.