diff --git a/chi/container.py b/chi/container.py index 084aa05..bd854af 100644 --- a/chi/container.py +++ b/chi/container.py @@ -188,7 +188,7 @@ def delete(self): None """ if self.id: - destroy_container(self.id) + destroy_container(self.id, force=True) self.id = None self._status = None @@ -478,7 +478,7 @@ def snapshot_container( return zun().containers.commit(container_ref, repository, tag=tag)["uuid"] -def destroy_container(container_ref: "str"): +def destroy_container(container_ref: "str", stop=False, force=False): """ .. deprecated:: 1.0 @@ -489,7 +489,7 @@ def destroy_container(container_ref: "str"): Args: container_ref (str): The name or ID of the container. """ - return zun().containers.delete(container_ref, stop=True) + return zun().containers.delete(container_ref, stop=stop, force=force) def get_logs(container_ref: "str", stdout=True, stderr=True): diff --git a/tests/test_container.py b/tests/test_container.py index cfd1cb8..60a7f9c 100644 --- a/tests/test_container.py +++ b/tests/test_container.py @@ -113,6 +113,18 @@ def test_download_extracts_tar_and_writes_file(mocker): assert f.read() == file_content +def test_delete_calls_force(mocker): + destroy_mock = mocker.patch("chi.container.destroy_container") + container = Container(name="test", image_ref="img") + container.id = "fake-id" + + container.delete() + + destroy_mock.assert_called_once_with("fake-id", force=True) + assert container.id is None + assert container._status is None + + def test_submit_idempotent_returns_existing_without_create(mocker): # idempotent=true, wait=true chi_container = Container(name="dup-name", image_ref="img")