44
55from testcontainers .core .container import DockerContainer
66from testcontainers .core .exceptions import ContainerStartException
7+ from testcontainers .core .waiting_utils import WaitStrategy
78
89from .sql_utils import SqlConnectWaitStrategy
910
@@ -16,9 +17,21 @@ class SqlContainer(DockerContainer):
1617
1718 This class can serve as a base for database-specific container implementations.
1819 It provides connection management, URL construction, and basic lifecycle methods.
19- Database connection readiness is automatically handled by ConnectWaitStrategy .
20+ Database connection readiness is automatically handled by the provided wait strategy .
2021 """
2122
23+ def __init__ (self , image : str , wait_strategy : Optional [WaitStrategy ] = None , ** kwargs ):
24+ """
25+ Initialize SqlContainer with optional wait strategy.
26+
27+ Args:
28+ image: Docker image name
29+ wait_strategy: Wait strategy for SQL database connectivity (defaults to SqlConnectWaitStrategy)
30+ **kwargs: Additional arguments passed to DockerContainer
31+ """
32+ super ().__init__ (image , ** kwargs )
33+ self .wait_strategy = wait_strategy or SqlConnectWaitStrategy ()
34+
2235 def _create_connection_url (
2336 self ,
2437 dialect : str ,
@@ -99,7 +112,7 @@ def start(self) -> "SqlContainer":
99112
100113 try :
101114 self ._configure ()
102- self .waiting_for (SqlConnectWaitStrategy () )
115+ self .waiting_for (self . wait_strategy )
103116 super ().start ()
104117 self ._transfer_seed ()
105118 logger .info ("Database container started successfully" )
0 commit comments