@@ -17,11 +17,12 @@ def test_docker_container_reuse_default():
1717 wait_for_logs (container , "Hello from Docker!" )
1818
1919 assert container ._reuse == False
20- assert testcontainers_config .tc_properties_testcontainers_reuse_enable == False
20+ assert testcontainers_config .tc_properties_testcontainers_reuse_enable () == False
2121 assert Reaper ._socket is not None
2222
2323 container .stop ()
2424 containers = DockerClient ().client .containers .list (all = True )
25+ assert container ._container is not None
2526 assert container ._container .id not in [container .id for container in containers ]
2627
2728
@@ -33,16 +34,13 @@ def test_docker_container_with_reuse_reuse_disabled(caplog):
3334 wait_for_logs (container , "Hello from Docker!" )
3435
3536 assert container ._reuse == True
36- assert testcontainers_config .tc_properties_testcontainers_reuse_enable == False
37- assert (
38- "Reuse was requested (`with_reuse`) but the environment does not support the "
39- + "reuse of containers. To enable container reuse, add "
40- + "'testcontainers.reuse.enable=true' to '~/.testcontainers.properties'."
41- ) in caplog .text
37+ assert testcontainers_config .tc_properties_testcontainers_reuse_enable () == False
38+ assert ("Reuse was requested (`with_reuse`) but the environment does not support the " ) in caplog .text
4239 assert Reaper ._socket is not None
4340
4441 container .stop ()
4542 containers = DockerClient ().client .containers .list (all = True )
43+ assert container ._container is not None
4644 assert container ._container .id not in [container .id for container in containers ]
4745
4846
@@ -57,11 +55,12 @@ def test_docker_container_without_reuse_reuse_enabled(monkeypatch):
5755 wait_for_logs (container , "Hello from Docker!" )
5856
5957 assert container ._reuse == False
60- assert testcontainers_config .tc_properties_testcontainers_reuse_enable == True
58+ assert testcontainers_config .tc_properties_testcontainers_reuse_enable () == True
6159 assert Reaper ._socket is not None
6260
6361 container .stop ()
6462 containers = DockerClient ().client .containers .list (all = True )
63+ assert container ._container is not None
6564 assert container ._container .id not in [container .id for container in containers ]
6665
6766
@@ -78,7 +77,9 @@ def test_docker_container_with_reuse_reuse_enabled(monkeypatch):
7877 assert Reaper ._socket is None
7978
8079 containers = DockerClient ().client .containers .list (all = True )
80+ assert container ._container is not None
8181 assert container ._container .id in [container .id for container in containers ]
82+
8283 # Cleanup after keeping container alive (with_reuse)
8384 container .stop ()
8485
@@ -91,8 +92,10 @@ def test_docker_container_with_reuse_reuse_enabled_same_id(monkeypatch):
9192 monkeypatch .setattr (testcontainers_config , "tc_properties" , tc_properties_mock )
9293
9394 container_1 = DockerContainer ("hello-world" ).with_reuse ().start ()
95+ assert container_1 ._container is not None
9496 id_1 = container_1 ._container .id
9597 container_2 = DockerContainer ("hello-world" ).with_reuse ().start ()
98+ assert container_2 ._container is not None
9699 id_2 = container_2 ._container .id
97100 assert Reaper ._socket is None
98101 assert id_1 == id_2
@@ -104,14 +107,16 @@ def test_docker_container_with_reuse_reuse_enabled_same_id(monkeypatch):
104107def test_docker_container_labels_hash_default ():
105108 # w/out reuse
106109 with DockerContainer ("hello-world" ) as container :
107- assert container ._container .labels ["hash" ] == ""
110+ assert container ._container is not None
111+ assert "hash" not in container ._container .labels .keys ()
108112
109113
110114def test_docker_container_labels_hash (monkeypatch ):
111115 tc_properties_mock = testcontainers_config .tc_properties | {"testcontainers.reuse.enable" : "true" }
112116 monkeypatch .setattr (testcontainers_config , "tc_properties" , tc_properties_mock )
113117 expected_hash = "1bade17a9d8236ba71ffbb676f2ece3fb419ea0e6adb5f82b5a026213c431d8e"
114118 with DockerContainer ("hello-world" ).with_reuse () as container :
119+ assert container ._container is not None
115120 assert container ._container .labels ["hash" ] == expected_hash
116121
117122
@@ -124,6 +129,7 @@ def test_docker_client_find_container_by_hash_existing(monkeypatch):
124129 tc_properties_mock = testcontainers_config .tc_properties | {"testcontainers.reuse.enable" : "true" }
125130 monkeypatch .setattr (testcontainers_config , "tc_properties" , tc_properties_mock )
126131 with DockerContainer ("hello-world" ).with_reuse () as container :
132+ assert container ._container is not None
127133 hash_ = container ._container .labels ["hash" ]
128134 found_container = DockerClient ().find_container_by_hash (hash_ )
129135 assert isinstance (found_container , Container )
0 commit comments