Skip to content

Commit

Permalink
DerivedContainer inhertis container_id, url from the base on prepare
Browse files Browse the repository at this point in the history
If the base is just a container image, then we want the url property to be set
instead of the container_id as otherwise the _build_tag property will be
`pytest_container:$url`
  • Loading branch information
dcermak committed Aug 8, 2023
1 parent 0d44efc commit d7cb602
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pytest_container/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ def prepare_container(
# do not build containers without a containerfile and where no build
# tags are added
if not self.containerfile and not self.add_build_tags:
self.container_id = str(self.get_base())
base = self.get_base()
self.container_id, self.url = base.container_id, base.url
return

with tempfile.TemporaryDirectory() as tmpdirname:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def test_lockfile_path(pytestconfig: pytest.Config) -> None:
:py:attr:`~pytest_container.ContainerBase.container_id` set.
"""
cont = DerivedContainer(base=images.OPENSUSE_BUSYBOX_URL, containerfile="")
cont = DerivedContainer(
base=images.OPENSUSE_BUSYBOX_URL, containerfile="ENV BAZ=1"
)
original_lock_fname = cont.filelock_filename

cont.prepare_container(pytestconfig.rootpath)
Expand All @@ -67,3 +69,9 @@ def test_lockfile_unique() -> None:
base=images.OPENSUSE_BUSYBOX_URL, containerfile="ENV foobar=1"
)
assert cont1.filelock_filename != cont2.filelock_filename


def test_derived_container_build_tag(pytestconfig: pytest.Config) -> None:
cont = DerivedContainer(base=images.OPENSUSE_BUSYBOX_URL)
cont.prepare_container(pytestconfig.rootpath)
assert cont._build_tag == images.OPENSUSE_BUSYBOX_URL
3 changes: 2 additions & 1 deletion tests/test_container_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def test_container_without_containerfile_and_without_tags_not_rebuild(
and not container.container.add_build_tags
)
assert container.container.get_base() == LEAP
assert container.container.container_id == LEAP.url
assert container.container.url == LEAP.url
assert container.container._build_tag == LEAP.url


@pytest.mark.parametrize("container", [LEAP_WITH_TAG], indirect=True)
Expand Down

0 comments on commit d7cb602

Please sign in to comment.