@@ -21,6 +21,7 @@ def test_docker_container_reuse_default():
21
21
def test_docker_container_with_reuse_reuse_disabled ():
22
22
with DockerContainer ("hello-world" ).with_reuse () as container :
23
23
assert container ._reuse == True
24
+ assert testcontainers_config .tc_properties_testcontainers_reuse_enable == False
24
25
id = container ._container .id
25
26
wait_for_logs (container , "Hello from Docker!" )
26
27
containers = DockerClient ().client .containers .list (all = True )
@@ -30,6 +31,7 @@ def test_docker_container_with_reuse_reuse_disabled():
30
31
def test_docker_container_with_reuse_reuse_enabled_ryuk_enabled (monkeypatch ):
31
32
# Make sure Ryuk cleanup is not active from previous test runs
32
33
Reaper .delete_instance ()
34
+
33
35
tc_properties_mock = testcontainers_config .tc_properties | {"testcontainers.reuse.enable" : "true" }
34
36
monkeypatch .setattr (testcontainers_config , "tc_properties" , tc_properties_mock )
35
37
monkeypatch .setattr (testcontainers_config , "ryuk_reconnection_timeout" , "0.1s" )
@@ -52,11 +54,12 @@ def test_docker_container_with_reuse_reuse_enabled_ryuk_enabled(monkeypatch):
52
54
def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled (monkeypatch ):
53
55
# Make sure Ryuk cleanup is not active from previous test runs
54
56
Reaper .delete_instance ()
57
+
55
58
tc_properties_mock = testcontainers_config .tc_properties | {"testcontainers.reuse.enable" : "true" }
56
59
monkeypatch .setattr (testcontainers_config , "tc_properties" , tc_properties_mock )
57
60
monkeypatch .setattr (testcontainers_config , "ryuk_disabled" , True )
61
+
58
62
with DockerContainer ("hello-world" ).with_reuse () as container :
59
- assert container ._reuse == True
60
63
id = container ._container .id
61
64
wait_for_logs (container , "Hello from Docker!" )
62
65
containers = DockerClient ().client .containers .list (all = True )
@@ -65,6 +68,22 @@ def test_docker_container_with_reuse_reuse_enabled_ryuk_disabled(monkeypatch):
65
68
container ._container .remove (force = True )
66
69
67
70
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
+
68
87
def test_docker_container_labels_hash ():
69
88
expected_hash = "91fde3c09244e1d3ec6f18a225b9261396b9a1cb0f6365b39b9795782817c128"
70
89
with DockerContainer ("hello-world" ).with_reuse () as container :
0 commit comments