Skip to content

Conversation

@pmorch
Copy link

@pmorch pmorch commented Dec 27, 2025

fix(core): Use WaitStrategy internally for wait_for function

Summary

Refactor the deprecated wait_for function to use the new WaitStrategy system internally instead of the @wait_container_is_ready decorator.

This fixes the import-time deprecation warning from #874.

See alexanderankin's comment stating core should no longer warn, and jonaslb's reply identifying that wait_for is still decorated with @wait_container_is_ready at module level, so it generates a warning.

Problem

The wait_for function was decorated with @wait_container_is_ready(), which emits a deprecation warning at decoration time (import time), not when the function is called. This caused warnings even when users never used wait_for.

Reproducer

mkdir /tmp/reproduce && cd /tmp/reproduce
echo 'import testcontainers.core.waiting_utils
def test_import(): pass' > test_import.py
uv run --with testcontainers --with pytest pytest test_import.py
=============================== warnings summary ===============================
waiting_utils.py:215: DeprecationWarning: The @wait_container_is_ready decorator
  is deprecated and will be removed in a future version...
    @wait_container_is_ready()

1 passed, 1 warning

Note: wait_for is never called - the warning is emitted just by importing the module.

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 testcontainers#874
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.59%. Comparing base (2d9eee3) to head (0d1cee7).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
core/testcontainers/core/waiting_utils.py 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #942      +/-   ##
==========================================
- Coverage   78.18%   77.59%   -0.59%     
==========================================
  Files          14       14              
  Lines        1210     1214       +4     
  Branches      187      187              
==========================================
- Hits          946      942       -4     
- Misses        222      231       +9     
+ Partials       42       41       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant