mirror of https://github.com/docker/docker-py.git
Merge a494201e6f
into db7f8b8bb6
This commit is contained in:
commit
5b95dd7582
|
@ -898,7 +898,10 @@ class ContainerCollection(Collection):
|
|||
if exit_status != 0:
|
||||
out = None
|
||||
if not kwargs.get('auto_remove'):
|
||||
out = container.logs(stdout=False, stderr=True)
|
||||
if not kwargs.get('tty'):
|
||||
out = container.logs(stdout=False, stderr=True)
|
||||
else:
|
||||
out = container.logs(stdout=True, stderr=True)
|
||||
|
||||
if remove:
|
||||
container.remove()
|
||||
|
|
|
@ -34,6 +34,15 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
|||
assert "alpine" in cm.exconly()
|
||||
assert "No such file or directory" in cm.exconly()
|
||||
|
||||
def test_run_with_error_with_tty(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
with pytest.raises(docker.errors.ContainerError) as cm:
|
||||
client.containers.run("alpine", "cat /test", remove=True, tty=True)
|
||||
assert cm.value.exit_status == 1
|
||||
assert "cat /test" in cm.exconly()
|
||||
assert "alpine" in cm.exconly()
|
||||
assert "No such file or directory" in cm.exconly()
|
||||
|
||||
def test_run_with_image_that_does_not_exist(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
with pytest.raises(docker.errors.ImageNotFound):
|
||||
|
|
|
@ -270,6 +270,16 @@ class ContainerCollectionTest(unittest.TestCase):
|
|||
assert cm.value.exit_status == 1
|
||||
assert "some error" in cm.exconly()
|
||||
|
||||
def test_run_with_error_and_tty(self):
|
||||
client = make_fake_client()
|
||||
client.api.logs.return_value = "some error"
|
||||
client.api.wait.return_value = {'StatusCode': 1}
|
||||
|
||||
with pytest.raises(docker.errors.ContainerError) as cm:
|
||||
client.containers.run('alpine', 'echo hello world', tty=True)
|
||||
assert cm.value.exit_status == 1
|
||||
assert "some error" in cm.exconly()
|
||||
|
||||
def test_run_with_image_object(self):
|
||||
client = make_fake_client()
|
||||
image = client.images.get(FAKE_IMAGE_ID)
|
||||
|
|
Loading…
Reference in New Issue