Skip to content

Commit

Permalink
Fix ImageCollectionTest.test_pull_multiple flakiness
Browse files Browse the repository at this point in the history
The ImageCollectionTest.test_pull_multiple test performs a `docker pull` without
a `:tag` specified) to pull all tags of the given repository (image).

After pulling the image, the image(s) pulled are checked to verify if the list
of images contains the `:latest` tag.

However, the test assumes that all tags of the image are tags for the same
version of the image (same digest), and thus a *single* image is returned, which
is not always the case.

Currently, the `hello-world:latest` and `hello-world:linux` tags point to a
different digest, therefore the `client.images.pull()` returns multiple images:
one image for digest, making the test fail:

    =================================== FAILURES ===================================
    ____________________ ImageCollectionTest.test_pull_multiple ____________________
    tests/integration/models_images_test.py:90: in test_pull_multiple
        assert len(images) == 1
    E   AssertionError: assert 2 == 1
    E    +  where 2 = len([<Image: 'hello-world:linux'>, <Image: 'hello-world:latest'>])

This patch updates the test to not assume a single image is returned, and instead
loop through the list of images and check if any of the images contains the
`:latest` tag.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jan 3, 2020
1 parent a0b9c3d commit 39c1fbb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/integration/models_images_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ def test_pull_with_sha(self):
def test_pull_multiple(self):
client = docker.from_env(version=TEST_API_VERSION)
images = client.images.pull('hello-world')
assert len(images) == 1
assert 'hello-world:latest' in images[0].attrs['RepoTags']
assert len(images) >= 1
found = False
for img in images:
if 'hello-world:latest' in img.attrs['RepoTags']:
found = True
break

assert found

def test_load_error(self):
client = docker.from_env(version=TEST_API_VERSION)
Expand Down

0 comments on commit 39c1fbb

Please sign in to comment.