testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Bug: HealthcheckWaitStrategy returns error with DockerCompose

Open reyescabello opened this issue 2 months ago • 1 comments

Describe the bug

When applying a 'waiting_for' to a DockerCompose object with a HealthcheckWaitStrategy, it returns an AttributeError: “ComposeContainer” object has no attribute “attrs”.

To Reproduce

import os
from testcontainers.compose import DockerCompose
from testcontainers.core.wait_strategies import HealthcheckWaitStrategy

BASE_DIR = os.path.dirname(__file__)

compose = DockerCompose(context=BASE_DIR, compose_file_name = "docker-compose.yml")
compose.waiting_for({"web": HealthcheckWaitStrategy().with_startup_timeout(60)})
compose.start()

docker-compose.yml:

version: '3.8'
services:
  web:
    image: nginx
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Traceback:

Traceback (most recent call last):
  File "<path>/test.py", line 9, in <module>
    compose.start()
  File "testcontainers/compose/compose.py", line 303, in start
    strategy.wait_until_ready(container)
  File "testcontainers/core/wait_strategies.py", line 487, in wait_until_ready
    health = wrapped.attrs.get("State", {}).get("Health", {})
             ^^^^^^^^^^^^^
AttributeError: 'ComposeContainer' object has no attribute 'attrs'

Runtime environment

$ uname -a
Linux kali 6.8.0-85-generic #85-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 18 15:26:59 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 3.12.1
$ poetry show | grep testcontainers
testcontainers                                  4.13.2 

reyescabello avatar Oct 15 '25 10:10 reyescabello

Hello! Are there any updates on the PR?

reyescabello avatar Nov 17 '25 13:11 reyescabello