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

fix(core): use auto_remove=True with reaper instance #499

Merged
merged 1 commit into from
Mar 24, 2024
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
2 changes: 1 addition & 1 deletion core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _create_instance(cls) -> "Reaper":
.with_name(f"testcontainers-ryuk-{SESSION_ID}")
.with_exposed_ports(8080)
.with_volume_mapping(RYUK_DOCKER_SOCKET, "/var/run/docker.sock", "rw")
.with_kwargs(privileged=RYUK_PRIVILEGED)
.with_kwargs(privileged=RYUK_PRIVILEGED, auto_remove=True)
.start()
)
wait_for_logs(Reaper._container, r".* Started!")
Expand Down
15 changes: 14 additions & 1 deletion core/tests/test_ryuk.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from contextlib import contextmanager

import pytest

from testcontainers.core import container
from testcontainers.core.container import Reaper
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for_logs


@pytest.mark.skip("invalid test - ryuk logs 'Removed' right before exiting")
def test_wait_for_reaper():
container = DockerContainer("hello-world").start()
wait_for_logs(container, "Hello from Docker!")
Expand All @@ -17,8 +22,16 @@ def test_wait_for_reaper():
Reaper.delete_instance()


@contextmanager
def reset_reaper_instance():
old_value = Reaper._instance
Reaper._instance = None
yield
Reaper._instance = old_value


def test_container_without_ryuk(monkeypatch):
monkeypatch.setattr(container, "RYUK_DISABLED", True)
with DockerContainer("hello-world") as cont:
with reset_reaper_instance(), DockerContainer("hello-world") as cont:
wait_for_logs(cont, "Hello from Docker!")
assert Reaper._instance is None