@@ -91,11 +91,10 @@ def collect_alerts(alert_queue: queue.Queue, car_ids: list[str], timeout: float
9191 return alerts
9292
9393
94- def test_accident_directional_notification ():
95- random_id = str (uuid .uuid4 ())[:8 ]
96- accident_car = f"accident-car-{ random_id } "
97- car_behind = f"car-behind-{ random_id } "
98- car_ahead = f"car-ahead-{ random_id } "
94+ def test_accident_directional_notification (get_car_id ):
95+ accident_car = get_car_id ("accident-car" )
96+ car_behind = get_car_id ("car-behind" )
97+ car_ahead = get_car_id ("car-ahead" )
9998
10099 ensure_car_exists (accident_car )
101100 ensure_car_exists (car_behind )
@@ -185,6 +184,17 @@ def other_cars_thread():
185184 time .sleep (2 )
186185 alerts = collect_alerts (alert_queue , [car_behind , car_ahead ], timeout = ALERT_TIMEOUT )
187186
187+ # Remove car device files to avoid interference with next test
188+ accident_car_file = SIM_DIR / "devices" / f"{ accident_car } .json"
189+ car_behind_file = SIM_DIR / "devices" / f"{ car_behind } .json"
190+ car_ahead_file = SIM_DIR / "devices" / f"{ car_ahead } .json"
191+ if accident_car_file .exists ():
192+ accident_car_file .unlink ()
193+ if car_behind_file .exists ():
194+ car_behind_file .unlink ()
195+ if car_ahead_file .exists ():
196+ car_ahead_file .unlink ()
197+
188198 # Assertions
189199 assert len (alerts [car_behind ]) > 0 , (
190200 f"Car BEHIND should receive accident alerts. "
@@ -197,17 +207,6 @@ def other_cars_thread():
197207 f"Got { len (alerts [car_ahead ])} alerts."
198208 )
199209
200- # Remove car device files to avoid interference with next test
201- accident_car_file = SIM_DIR / "devices" / f"{ accident_car } .json"
202- car_behind_file = SIM_DIR / "devices" / f"{ car_behind } .json"
203- car_ahead_file = SIM_DIR / "devices" / f"{ car_ahead } .json"
204- if accident_car_file .exists ():
205- accident_car_file .unlink ()
206- if car_behind_file .exists ():
207- car_behind_file .unlink ()
208- if car_ahead_file .exists ():
209- car_ahead_file .unlink ()
210-
211210
212211if __name__ == "__main__" :
213212 test_accident_directional_notification ()
0 commit comments