From 0d1cee71793a2d389177fbd3f375799856249828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Valdemar=20M=C3=B8rch?= Date: Sat, 27 Dec 2025 23:35:46 +0100 Subject: [PATCH] fix(core): Use WaitStrategy internally for wait_for function Refactor the deprecated wait_for function to use the new WaitStrategy system internally instead of the @wait_container_is_ready decorator. The decorator emitted a deprecation warning at decoration time (import time), causing warnings even when users never called wait_for. Replace with an internal CallableWaitStrategy that uses WaitStrategy._poll() for retry logic. This follows the intended migration path to the new system. Fixes https://github.com/testcontainers/testcontainers-python/issues/874 --- core/testcontainers/core/waiting_utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/testcontainers/core/waiting_utils.py b/core/testcontainers/core/waiting_utils.py index 9942854a..b186c0af 100644 --- a/core/testcontainers/core/waiting_utils.py +++ b/core/testcontainers/core/waiting_utils.py @@ -212,7 +212,6 @@ def wrapper(wrapped: Callable[..., Any], instance: Any, args: list[Any], kwargs: return cast("Callable[[F], F]", wrapper) -@wait_container_is_ready() def wait_for(condition: Callable[..., bool]) -> bool: warnings.warn( "The wait_for function is deprecated and will be removed in a future version. " @@ -222,7 +221,15 @@ def wait_for(condition: Callable[..., bool]) -> bool: DeprecationWarning, stacklevel=2, ) - return condition() + + class CallableWaitStrategy(WaitStrategy): + def wait_until_ready(self, container: WaitStrategyTarget) -> None: + pass # Required by ABC, but unused + + strategy = CallableWaitStrategy() + if not strategy._poll(condition): + raise TimeoutError(f"Condition not satisfied within {strategy._startup_timeout}s") + return True _NOT_EXITED_STATUSES = {"running", "created"}