@@ -68,6 +68,9 @@ class TestContainerStartupError(Exception):
6868 """Raised when any test container fails to start."""
6969 pass
7070
71+ class TestContainerTeardownError (Exception ):
72+ """Raised when any test container fails to teardown."""
73+ pass
7174
7275def validate_enrichment_with_bigtable ():
7376 expected = '''[START enrichment_with_bigtable]
@@ -186,7 +189,7 @@ def test_enrichment_with_external_pg(self, mock_stdout):
186189 output = mock_stdout .getvalue ().splitlines ()
187190 expected = validate_enrichment_with_external_pg ()
188191 self .assertEqual (output , expected )
189- except TestContainerStartupError as e :
192+ except ( TestContainerStartupError , TestContainerTeardownError ) as e :
190193 raise unittest .SkipTest (str (e ))
191194 except Exception as e :
192195 self .fail (f"Test failed with unexpected error: { e } " )
@@ -199,7 +202,7 @@ def test_enrichment_with_external_mysql(self, mock_stdout):
199202 output = mock_stdout .getvalue ().splitlines ()
200203 expected = validate_enrichment_with_external_mysql ()
201204 self .assertEqual (output , expected )
202- except TestContainerStartupError as e :
205+ except ( TestContainerStartupError , TestContainerTeardownError ) as e :
203206 raise unittest .SkipTest (str (e ))
204207 except Exception as e :
205208 self .fail (f"Test failed with unexpected error: { e } " )
@@ -212,7 +215,7 @@ def test_enrichment_with_external_sqlserver(self, mock_stdout):
212215 output = mock_stdout .getvalue ().splitlines ()
213216 expected = validate_enrichment_with_external_sqlserver ()
214217 self .assertEqual (output , expected )
215- except TestContainerStartupError as e :
218+ except ( TestContainerStartupError , TestContainerTeardownError ) as e :
216219 raise unittest .SkipTest (str (e ))
217220 except Exception as e :
218221 self .fail (f"Test failed with unexpected error: { e } " )
@@ -227,7 +230,7 @@ def test_enrichment_with_milvus(self, mock_stdout):
227230 output = parse_chunk_strings (output )
228231 expected = parse_chunk_strings (expected )
229232 assert_chunks_equivalent (output , expected )
230- except TestContainerStartupError as e :
233+ except ( TestContainerStartupError , TestContainerTeardownError ) as e :
231234 raise unittest .SkipTest (str (e ))
232235 except Exception as e :
233236 self .fail (f"Test failed with unexpected error: { e } " )
@@ -373,19 +376,17 @@ def post_sql_enrichment_test(res: CloudSQLEnrichmentTestDataConstruct):
373376 def pre_milvus_enrichment () -> MilvusDBContainerInfo :
374377 try :
375378 db = MilvusEnrichmentTestHelper .start_db_container ()
376- except Exception as e :
377- raise TestContainerStartupError (
378- f"Milvus container failed to start: { str (e )} " )
379-
380- connection_params = MilvusConnectionParameters (
379+ connection_params = MilvusConnectionParameters (
381380 uri = db .uri ,
382381 user = db .user ,
383382 password = db .password ,
384383 db_id = db .id ,
385384 token = db .token )
386-
387- collection_name = MilvusEnrichmentTestHelper .initialize_db_with_data (
385+ collection_name = MilvusEnrichmentTestHelper .initialize_db_with_data (
388386 connection_params )
387+ except Exception as e :
388+ raise TestContainerStartupError (
389+ f"Milvus container failed to start: { str (e )} " )
389390
390391 # Setup environment variables for db and collection configuration. This will
391392 # be used downstream by the milvus enrichment handler.
@@ -400,7 +401,12 @@ def pre_milvus_enrichment() -> MilvusDBContainerInfo:
400401
401402 @staticmethod
402403 def post_milvus_enrichment (db : MilvusDBContainerInfo ):
403- MilvusEnrichmentTestHelper .stop_db_container (db )
404+ try :
405+ MilvusEnrichmentTestHelper .stop_db_container (db )
406+ except Exception :
407+ raise TestContainerTeardownError (
408+ f"Milvus container failed to tear down: { str (e )} " )
409+
404410 os .environ .pop ('MILVUS_VECTOR_DB_URI' , None )
405411 os .environ .pop ('MILVUS_VECTOR_DB_USER' , None )
406412 os .environ .pop ('MILVUS_VECTOR_DB_PASSWORD' , None )
0 commit comments