Skip to content

Commit e031cf0

Browse files
authored
Merge pull request #3290 from laurazard/exec-no-executable-exit-code
tests/exec: expect 127 exit code for missing executable
2 parents a365202 + b126547 commit e031cf0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/integration/models_containers_test.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,26 @@ 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(
359368
"alpine", "sh -c 'sleep 60'", detach=True
360369
)
361370
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
364376

365377
def test_kill(self):
366378
client = docker.from_env(version=TEST_API_VERSION)

0 commit comments

Comments
 (0)