@@ -98,15 +98,32 @@ def spin_up_airflow_environment(tmp_path_factory):
9898 # as it is already available and loaded using prepare_breeze_and_image step in workflow
9999 pull = False if DOCKER_IMAGE .startswith ("ghcr.io/apache/airflow/main/" ) else True
100100
101- console .print (f"[blue]Spinning up airflow environment using { DOCKER_IMAGE } " )
102- compose_instance = DockerCompose (tmp_dir , compose_file_name = compose_file_names , pull = pull )
101+ try :
102+ console .print (f"[blue]Spinning up airflow environment using { DOCKER_IMAGE } " )
103+ compose_instance = DockerCompose (tmp_dir , compose_file_name = compose_file_names , pull = pull )
103104
104- compose_instance .start ()
105+ compose_instance .start ()
106+
107+ compose_instance .wait_for (f"http://{ DOCKER_COMPOSE_HOST_PORT } /api/v2/version" )
108+ compose_instance .exec_in_container (
109+ command = ["airflow" , "dags" , "reserialize" ], service_name = "airflow-dag-processor"
110+ )
111+
112+ except Exception :
113+ console .print ("[red]Failed to start docker compose" )
114+ _print_logs (compose_instance )
115+ compose_instance .stop ()
116+ raise
105117
106- compose_instance .wait_for (f"http://{ DOCKER_COMPOSE_HOST_PORT } /api/v2/version" )
107- compose_instance .exec_in_container (
108- command = ["airflow" , "dags" , "reserialize" ], service_name = "airflow-dag-processor"
109- )
118+
119+ def _print_logs (compose_instance ):
120+ containers = compose_instance .get_containers ()
121+ for container in containers :
122+ service = container .Service
123+ stdout , _ = compose_instance .get_logs (service )
124+ console .print (f"::group:: { service } Logs" )
125+ console .print (f"[red]{ stdout } " )
126+ console .print ("::endgroup::" )
110127
111128
112129def pytest_sessionstart (session ):
@@ -143,6 +160,10 @@ def pytest_sessionfinish(session, exitstatus):
143160 if airflow_logs_path is not None :
144161 copytree (airflow_logs_path , LOGS_FOLDER , dirs_exist_ok = True )
145162
163+ # If any test failures lets print the services logs
164+ if any (r ["status" ] == "failed" for r in test_results ):
165+ _print_logs (compose_instance = compose_instance )
166+
146167 if compose_instance :
147168 if not os .environ .get ("SKIP_DOCKER_COMPOSE_DELETION" ):
148169 compose_instance .stop ()
0 commit comments