Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DerivedContainer inhertis container_id, url from the base on prepare #150

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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