diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index d40eddad..dc5470c3 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -226,15 +226,17 @@ def get_container_host_ip(self) -> str: connection_mode: ConnectionMode connection_mode = self.get_docker_client().get_connection_mode() - # mypy: - container = self._container - assert container is not None - if connection_mode == ConnectionMode.docker_host: return self.get_docker_client().host() elif connection_mode == ConnectionMode.gateway_ip: + # mypy: + container = self._container + assert container is not None return self.get_docker_client().gateway_ip(container.id) elif connection_mode == ConnectionMode.bridge_ip: + # mypy: + container = self._container + assert container is not None return self.get_docker_client().bridge_ip(container.id) else: # ensure that we covered all possible connection_modes