@@ -53,7 +53,6 @@ def mock_docker_client():
5353 mock_client .containers = mock_containers
5454 return mock_client
5555
56-
5756@pytest .fixture
5857def mock_container ():
5958 """Mock a Docker container."""
@@ -285,15 +284,22 @@ def test_init(self):
285284 assert container .executor == executor
286285 assert container .extra_env == {"EXTRA" : "value" }
287286
288- @patch ("nemo_run.core.execution.docker.DockerContainer.run" )
289- def test_run (self , mock_run , mock_docker_client , mock_container ):
287+ @patch ("docker.DockerClient" )
288+ @patch ("nemo_run.core.execution.docker.ensure_network" )
289+ def test_run (
290+ self ,
291+ mock_client ,
292+ mock_ensure_network ,
293+ mock_docker_client ,
294+ mock_container ,
295+ ):
290296 """Test run method of DockerContainer."""
291297 executor = DockerExecutor (
292298 container_image = "test:latest" ,
293299 runtime = "nvidia" ,
294300 num_gpus = 2 ,
295301 shm_size = "8g" ,
296- ulimits = ["memlock:unlimited:unlimited " ],
302+ ulimits = ["memlock:0:123 " ],
297303 ipc_mode = "host" ,
298304 privileged = True ,
299305 volumes = ["/host:/container" ],
@@ -308,11 +314,21 @@ def test_run(self, mock_run, mock_docker_client, mock_container):
308314 extra_env = {"EXTRA" : "value" },
309315 )
310316
311- mock_run .return_value = mock_container
317+ mock_ensure_network .return_value = None
318+
319+ def mocked_run (* args , ** kwargs ):
320+ detach = kwargs .pop ('detach' , None )
321+ remove = kwargs .pop ('remove' , None )
322+ assert detach is True
323+ assert remove is True
324+
325+ mock_client .containers .run = mocked_run
326+
327+ container .run (mock_client , "job123" )
312328
313329 # Instead of actually calling run which would fail with the "unlimited" value,
314330 # we'll check that the container is properly set up
315- assert container .executor .ulimits == ["memlock:unlimited:unlimited " ]
331+ assert container .executor .ulimits == ["memlock:0:123 " ]
316332 assert container .extra_env == {"EXTRA" : "value" }
317333 assert container .executor .experiment_id == "exp123"
318334
0 commit comments