From 82cf95dec7045825dd8def7e8c4027810d58556c Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 14 Aug 2024 10:54:54 -0700 Subject: [PATCH 1/2] feat: add flag for exiting early while waiting for logs if the container exited --- core/testcontainers/core/waiting_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/testcontainers/core/waiting_utils.py b/core/testcontainers/core/waiting_utils.py index 82ea1f15..d81dc7ac 100644 --- a/core/testcontainers/core/waiting_utils.py +++ b/core/testcontainers/core/waiting_utils.py @@ -83,6 +83,7 @@ def wait_for_logs( timeout: float = config.timeout, interval: float = 1, predicate_streams_and: bool = False, + raise_on_exit: bool = False # ) -> float: """ @@ -117,4 +118,6 @@ def wait_for_logs( return duration if duration > timeout: raise TimeoutError(f"Container did not emit logs satisfying predicate in {timeout:.3f} " "seconds") + if raise_on_exit and container.get_wrapped_container().status != 'running': + raise RuntimeError(f"Container exited before emitting logs satisfying predicate") time.sleep(interval) From 8bc2cc4cdf3ffc5777a39d09470baeca5757926c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20B=C3=B6=C3=B6k?= <49250723+ArthurBook@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:52:54 -0700 Subject: [PATCH 2/2] fix: remove f from err msg string solves lint fail --- core/testcontainers/core/waiting_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/testcontainers/core/waiting_utils.py b/core/testcontainers/core/waiting_utils.py index d81dc7ac..2bd7806b 100644 --- a/core/testcontainers/core/waiting_utils.py +++ b/core/testcontainers/core/waiting_utils.py @@ -83,7 +83,7 @@ def wait_for_logs( timeout: float = config.timeout, interval: float = 1, predicate_streams_and: bool = False, - raise_on_exit: bool = False + raise_on_exit: bool = False, # ) -> float: """ @@ -118,6 +118,6 @@ def wait_for_logs( return duration if duration > timeout: raise TimeoutError(f"Container did not emit logs satisfying predicate in {timeout:.3f} " "seconds") - if raise_on_exit and container.get_wrapped_container().status != 'running': - raise RuntimeError(f"Container exited before emitting logs satisfying predicate") + if raise_on_exit and container.get_wrapped_container().status != "running": + raise RuntimeError("Container exited before emitting logs satisfying predicate") time.sleep(interval)