11from flask_socketio .test_client import SocketIOTestClient
22import docker
3+ from docker .errors import DockerException
34from . import falcon_test
45
56client = docker .from_env ()
@@ -13,27 +14,25 @@ def cleanup_container():
1314 container = client .containers .get ("fgcs_ardupilot_sitl" )
1415 container .stop ()
1516 container .remove ()
16- except docker . errors . NotFound :
17- pass
17+ except DockerException :
18+ pass # Container does not exist and therefore no cleanup required
1819
1920
2021@falcon_test ()
2122def test_start_docker_simulation_success (socketio_client : SocketIOTestClient ):
2223 """
2324 Test successfully starting the simulation using Docker.
2425 """
26+ cleanup_container ()
27+
2528 socketio_client .emit ("start_docker_simulation" , {"port" : 5763 })
2629 result = socketio_client .get_received ()[- 1 ]
2730
2831 assert result ["name" ] == "simulation_result"
2932 assert result ["args" ][0 ]["success" ] is True
3033 assert "Simulation started" in result ["args" ][0 ]["message" ]
3134
32- # Cleanup
33- socketio_client .emit ("stop_docker_simulation" )
34- stop_result = socketio_client .get_received ()[- 1 ]
35-
36- assert stop_result ["args" ][0 ]["success" ] is True
35+ cleanup_container ()
3736
3837
3938@falcon_test ()
@@ -73,6 +72,7 @@ def test_stop_docker_simulation(socketio_client: SocketIOTestClient):
7372 client .containers .run (
7473 "kushmakkapati/ardupilot_sitl" ,
7574 name = "fgcs_ardupilot_sitl" ,
75+ ports = {5765 : 5765 },
7676 detach = True ,
7777 tty = True ,
7878 )
@@ -84,8 +84,6 @@ def test_stop_docker_simulation(socketio_client: SocketIOTestClient):
8484 assert result ["args" ][0 ]["success" ] is True
8585 assert "Simulation stopped" in result ["args" ][0 ]["message" ]
8686
87- cleanup_container ()
88-
8987
9088@falcon_test ()
9189def test_build_command (socketio_client : SocketIOTestClient ):
0 commit comments