Skip to content

Commit 0d1cee7

Browse files
committed
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 #874
1 parent c785ecd commit 0d1cee7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

core/testcontainers/core/waiting_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def wrapper(wrapped: Callable[..., Any], instance: Any, args: list[Any], kwargs:
212212
return cast("Callable[[F], F]", wrapper)
213213

214214

215-
@wait_container_is_ready()
216215
def wait_for(condition: Callable[..., bool]) -> bool:
217216
warnings.warn(
218217
"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:
222221
DeprecationWarning,
223222
stacklevel=2,
224223
)
225-
return condition()
224+
225+
class CallableWaitStrategy(WaitStrategy):
226+
def wait_until_ready(self, container: WaitStrategyTarget) -> None:
227+
pass # Required by ABC, but unused
228+
229+
strategy = CallableWaitStrategy()
230+
if not strategy._poll(condition):
231+
raise TimeoutError(f"Condition not satisfied within {strategy._startup_timeout}s")
232+
return True
226233

227234

228235
_NOT_EXITED_STATUSES = {"running", "created"}

0 commit comments

Comments
 (0)