From 5f57cb6926e599ac06c31be74ccaeb9f55c83080 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Sat, 22 Feb 2025 00:25:59 +0000 Subject: [PATCH] Clarify container.remove() behaviour --- tagging/utils/docker_runner.py | 5 ++--- tests/utils/tracked_container.py | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tagging/utils/docker_runner.py b/tagging/utils/docker_runner.py index c202010951..adc9418d19 100644 --- a/tagging/utils/docker_runner.py +++ b/tagging/utils/docker_runner.py @@ -39,9 +39,8 @@ def __exit__( ) -> None: assert self.container is not None LOGGER.info(f"Removing container {self.container.name} ...") - if self.container: - self.container.remove(force=True) - LOGGER.info(f"Container {self.container.name} removed") + self.container.remove(force=True) + LOGGER.info(f"Container {self.container.name} removed") @staticmethod def run_simple_command( diff --git a/tests/utils/tracked_container.py b/tests/utils/tracked_container.py index 6942b4be8b..51a86afcad 100644 --- a/tests/utils/tracked_container.py +++ b/tests/utils/tracked_container.py @@ -92,5 +92,9 @@ def _lines_starting_with(logs: str, pattern: str) -> list[str]: def remove(self) -> None: """Kills and removes the tracked docker container.""" - if self.container: + if self.container is None: + LOGGER.info("No container to remove") + else: + LOGGER.info(f"Removing container {self.container.name} ...") self.container.remove(force=True) + LOGGER.info(f"Container {self.container.name} removed")