summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-03-05 10:26:50 +0100
committerTodd Gamblin <tgamblin@llnl.gov>2020-03-20 11:39:28 -0700
commit59a7963785b0e443d5682d497af373383876da20 (patch)
tree5a2248b06066380f020986aa3b02a87eb6d360c4 /lib
parent733f9f8cfa5814cd1df6c34cf7e70f460ce75ff4 (diff)
downloadspack-59a7963785b0e443d5682d497af373383876da20.tar.gz
spack-59a7963785b0e443d5682d497af373383876da20.tar.bz2
spack-59a7963785b0e443d5682d497af373383876da20.tar.xz
spack-59a7963785b0e443d5682d497af373383876da20.zip
Bugfix: resolve StopIteration message attribute failure (#15341)
Testing the install StopIteration exception resulted in an attribute error: AttributeError: 'StopIteration' object has no attribute 'message' This PR adds a unit test and resolves that error.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/spack/spack/installer.py2
-rw-r--r--lib/spack/spack/test/installer.py21
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py
index db82844cc5..bd38d11ea2 100755
--- a/lib/spack/spack/installer.py
+++ b/lib/spack/spack/installer.py
@@ -1154,7 +1154,7 @@ class PackageInstaller(object):
except StopIteration as e:
# A StopIteration exception means that do_install was asked to
# stop early from clients.
- tty.msg('{0} {1}'.format(self.pid, e.message))
+ tty.msg('{0} {1}'.format(self.pid, str(e)))
tty.msg('Package stage directory : {0}'
.format(pkg.stage.source_path))
diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py
index c261ca7a63..8c3a232f19 100644
--- a/lib/spack/spack/test/installer.py
+++ b/lib/spack/spack/test/installer.py
@@ -391,6 +391,27 @@ def test_install_task_use_cache(install_mockery, monkeypatch):
assert spec.package.name in installer.installed
+def test_install_task_stop_iter(install_mockery, monkeypatch, capfd):
+ """Test _install_task to cover the StopIteration exception."""
+ mock_err_msg = 'mock stop iteration'
+
+ def _raise(installer, pkg):
+ raise StopIteration(mock_err_msg)
+
+ spec, installer = create_installer('a')
+ task = create_build_task(spec.package)
+
+ monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', _true)
+ monkeypatch.setattr(inst.PackageInstaller, '_setup_install_dir', _raise)
+
+ installer._install_task(task)
+ out = capfd.readouterr()[0]
+
+ assert mock_err_msg in out
+ assert 'Package stage directory' in out
+ assert spec.package.stage.source_path in out
+
+
def test_release_lock_write_n_exception(install_mockery, tmpdir, capsys):
"""Test _release_lock for supposed write lock with exception."""
spec, installer = create_installer('trivial-install-test-package')