@@ -353,14 +353,26 @@ def test_exec_run_success(self):
353
353
assert exec_output [0 ] == 0
354
354
assert exec_output [1 ] == b"hello\n "
355
355
356
+ def test_exec_run_error_code_from_exec (self ):
357
+ client = docker .from_env (version = TEST_API_VERSION )
358
+ container = client .containers .run (
359
+ "alpine" , "sh -c 'sleep 20'" , detach = True
360
+ )
361
+ self .tmp_containers .append (container .id )
362
+ exec_output = container .exec_run ("sh -c 'exit 42'" )
363
+ assert exec_output [0 ] == 42
364
+
356
365
def test_exec_run_failed (self ):
357
366
client = docker .from_env (version = TEST_API_VERSION )
358
367
container = client .containers .run (
359
368
"alpine" , "sh -c 'sleep 60'" , detach = True
360
369
)
361
370
self .tmp_containers .append (container .id )
362
- exec_output = container .exec_run ("docker ps" )
363
- assert exec_output [0 ] == 126
371
+ exec_output = container .exec_run ("non-existent" )
372
+ # older versions of docker return `126` in the case that an exec cannot
373
+ # be started due to a missing executable. We're fixing this for the
374
+ # future, so accept both for now.
375
+ assert exec_output [0 ] == 127 or exec_output [0 ] == 126
364
376
365
377
def test_kill (self ):
366
378
client = docker .from_env (version = TEST_API_VERSION )
0 commit comments