Skip to content

Commit 17ee8e0

Browse files
test: additional testcase for reusable containers
1 parent bff1e3b commit 17ee8e0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

core/tests/test_reusable_containers.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_docker_container_reuse_default():
2121
def test_docker_container_with_reuse_reuse_disabled():
2222
with DockerContainer("hello-world").with_reuse() as container:
2323
assert container._reuse == True
24+
assert testcontainers_config.tc_properties_testcontainers_reuse_enable == False
2425
id = container._container.id
2526
wait_for_logs(container, "Hello from Docker!")
2627
containers = DockerClient().client.containers.list(all=True)
@@ -30,6 +31,7 @@ def test_docker_container_with_reuse_reuse_disabled():
3031
def test_docker_container_with_reuse_reuse_enabled_ryuk_enabled(monkeypatch):
3132
# Make sure Ryuk cleanup is not active from previous test runs
3233
Reaper.delete_instance()
34+
3335
tc_properties_mock = testcontainers_config.tc_properties | {"testcontainers.reuse.enable": "true"}
3436
monkeypatch.setattr(testcontainers_config, "tc_properties", tc_properties_mock)
3537
monkeypatch.setattr(testcontainers_config, "ryuk_reconnection_timeout", "0.1s")
@@ -52,11 +54,12 @@ def test_docker_container_with_reuse_reuse_enabled_ryuk_enabled(monkeypatch):
5254
def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled(monkeypatch):
5355
# Make sure Ryuk cleanup is not active from previous test runs
5456
Reaper.delete_instance()
57+
5558
tc_properties_mock = testcontainers_config.tc_properties | {"testcontainers.reuse.enable": "true"}
5659
monkeypatch.setattr(testcontainers_config, "tc_properties", tc_properties_mock)
5760
monkeypatch.setattr(testcontainers_config, "ryuk_disabled", True)
61+
5862
with DockerContainer("hello-world").with_reuse() as container:
59-
assert container._reuse == True
6063
id = container._container.id
6164
wait_for_logs(container, "Hello from Docker!")
6265
containers = DockerClient().client.containers.list(all=True)
@@ -65,6 +68,22 @@ def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled(monkeypatch):
6568
container._container.remove(force=True)
6669

6770

71+
def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled_same_id(monkeypatch):
72+
# Make sure Ryuk cleanup is not active from previous test runs
73+
Reaper.delete_instance()
74+
75+
tc_properties_mock = testcontainers_config.tc_properties | {"testcontainers.reuse.enable": "true"}
76+
monkeypatch.setattr(testcontainers_config, "tc_properties", tc_properties_mock)
77+
monkeypatch.setattr(testcontainers_config, "ryuk_disabled", True)
78+
79+
with DockerContainer("hello-world").with_reuse() as container:
80+
id = container._container.id
81+
with DockerContainer("hello-world").with_reuse() as container:
82+
assert id == container._container.id
83+
# Cleanup after keeping container alive (with_reuse)
84+
container._container.remove(force=True)
85+
86+
6887
def test_docker_container_labels_hash():
6988
expected_hash = "91fde3c09244e1d3ec6f18a225b9261396b9a1cb0f6365b39b9795782817c128"
7089
with DockerContainer("hello-world").with_reuse() as container:

0 commit comments

Comments
 (0)