This commit is contained in:
kshea21 2025-01-08 11:11:40 -08:00 committed by Gregory Becker
parent 11572c0caf
commit 1a19c09c55
No known key found for this signature in database
GPG Key ID: 2362541F6D14ED84
2 changed files with 8 additions and 4 deletions

View File

@ -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)

View File

@ -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()