From 1a19c09c558254f76b3fcdf41e14fb5a8eadae4e Mon Sep 17 00:00:00 2001 From: kshea21 Date: Wed, 8 Jan 2025 11:11:40 -0800 Subject: [PATCH] style --- lib/spack/spack/installer.py | 7 +++++-- lib/spack/spack/test/installer.py | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py index 3ddb08de8a1..1823c34b8a6 100644 --- a/lib/spack/spack/installer.py +++ b/lib/spack/spack/installer.py @@ -2226,8 +2226,11 @@ def complete_task(task) -> None: keep_prefix = install_args.get("keep_prefix") action = self._install_action(task) try: - self._complete_task(task, install_status) - active_tasks.remove(task) + try: + self._complete_task(task, install_status) + finally: + # Remove task from active_tasks on error or success + active_tasks.remove(task) # If we installed then we should keep the prefix stop_before_phase = getattr(pkg, "stop_before_phase", None) diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py index f9f3d20f273..d3fe3bb3bd3 100644 --- a/lib/spack/spack/test/installer.py +++ b/lib/spack/spack/test/installer.py @@ -984,6 +984,7 @@ class MyBuildException(Exception): _old_complete_task = None + def _install_fail_my_build_exception(installer, task, install_status, **kwargs): if task.pkg.name == "pkg-a": print("Raising MyBuildException for pkg-a") @@ -995,13 +996,13 @@ def _install_fail_my_build_exception(installer, task, install_status, **kwargs): def test_install_fail_single(install_mockery, mock_fetch, monkeypatch): """Test expected results for failure of single package.""" global _old_complete_task - + installer = create_installer(["pkg-a"], {"fake": True}) # Raise a KeyboardInterrupt error to trigger early termination _old_complete_task = inst.PackageInstaller._complete_task monkeypatch.setattr(inst.PackageInstaller, "_complete_task", _install_fail_my_build_exception) - + with pytest.raises(MyBuildException, match="mock internal package build error for pkg-a"): installer.install()