Skip to content

Commit b126547

Browse files
committed
tests/exec: add test for exit code from exec
Execs should return the exit code of the exec'd process, if it started. Signed-off-by: Laura Brehm <[email protected]>
1 parent 96ef4d3 commit b126547

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/integration/models_containers_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ def test_exec_run_success(self):
353353
assert exec_output[0] == 0
354354
assert exec_output[1] == b"hello\n"
355355

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+
356365
def test_exec_run_failed(self):
357366
client = docker.from_env(version=TEST_API_VERSION)
358367
container = client.containers.run(
@@ -363,7 +372,7 @@ def test_exec_run_failed(self):
363372
# older versions of docker return `126` in the case that an exec cannot
364373
# be started due to a missing executable. We're fixing this for the
365374
# future, so accept both for now.
366-
assert exec_output[0] == 127 or exec_output == 126
375+
assert exec_output[0] == 127 or exec_output[0] == 126
367376

368377
def test_kill(self):
369378
client = docker.from_env(version=TEST_API_VERSION)

0 commit comments

Comments
 (0)