Skip to content

Commit ad1575a

Browse files
committed
Required wait_strategy
1 parent a99045a commit ad1575a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

modules/generic/testcontainers/generic/sql.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from testcontainers.core.exceptions import ContainerStartException
77
from testcontainers.core.waiting_utils import WaitStrategy
88

9-
from .sql_utils import SqlConnectWaitStrategy
10-
119
logger = logging.getLogger(__name__)
1210

1311

@@ -20,17 +18,17 @@ class SqlContainer(DockerContainer):
2018
Database connection readiness is automatically handled by the provided wait strategy.
2119
"""
2220

23-
def __init__(self, image: str, wait_strategy: Optional[WaitStrategy] = None, **kwargs):
21+
def __init__(self, image: str, wait_strategy: WaitStrategy, **kwargs):
2422
"""
2523
Initialize SqlContainer with optional wait strategy.
2624
2725
Args:
2826
image: Docker image name
29-
wait_strategy: Wait strategy for SQL database connectivity (defaults to SqlConnectWaitStrategy)
27+
wait_strategy: Wait strategy for SQL database connectivity
3028
**kwargs: Additional arguments passed to DockerContainer
3129
"""
3230
super().__init__(image, **kwargs)
33-
self.wait_strategy = wait_strategy or SqlConnectWaitStrategy()
31+
self.wait_strategy = wait_strategy
3432

3533
def _create_connection_url(
3634
self,

modules/generic/tests/test_sql.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import pytest
2+
23
from testcontainers.core.exceptions import ContainerStartException
4+
from testcontainers.generic.sql_utils import SqlConnectWaitStrategy
35
from testcontainers.generic.sql import SqlContainer
46

57

68
class SimpleSqlContainer(SqlContainer):
79
"""Simple concrete implementation for testing."""
810

911
def __init__(self, image: str = "postgres:13"):
10-
super().__init__(image)
12+
super().__init__(image, wait_strategy=SqlConnectWaitStrategy())
1113
self.username = "testuser"
1214
self.password = "testpass"
1315
self.dbname = "testdb"
@@ -27,7 +29,7 @@ def _configure(self) -> None:
2729

2830
class TestSqlContainer:
2931
def test_abstract_methods_raise_not_implemented(self):
30-
container = SqlContainer("test:latest")
32+
container = SqlContainer("test:latest", SqlConnectWaitStrategy())
3133

3234
with pytest.raises(NotImplementedError):
3335
container.get_connection_url()
@@ -36,7 +38,7 @@ def test_abstract_methods_raise_not_implemented(self):
3638
container._configure()
3739

3840
def test_transfer_seed_default_behavior(self):
39-
container = SqlContainer("test:latest")
41+
container = SqlContainer("test:latest", SqlConnectWaitStrategy())
4042
# Should not raise an exception
4143
container._transfer_seed()
4244

0 commit comments

Comments
 (0)