1
1
from docker .models .containers import Container
2
2
from testcontainers .core .container import DockerContainer
3
3
from testcontainers .core .docker_client import DockerClient
4
+ from testcontainers .core .waiting_utils import wait_for_logs
4
5
5
6
6
7
def test_docker_container_reuse_default ():
@@ -11,17 +12,27 @@ def test_docker_container_reuse_default():
11
12
assert id not in [container .id for container in containers ]
12
13
13
14
14
- def test_docker_container_with_reuse ():
15
+ def test_docker_container_with_reuse_reuse_disabled ():
15
16
with DockerContainer ("hello-world" ).with_reuse () as container :
16
17
assert container ._reuse == True
17
18
id = container ._container .id
18
19
containers = DockerClient ().client .containers .list (all = True )
20
+ assert id not in [container .id for container in containers ]
21
+
22
+
23
+ def test_docker_container_with_reuse_reuse_enabled (monkeypatch ):
24
+ monkeypatch .setattr ("testcontainers.core.config.testcontainers_config.reuse_enabled" , True )
25
+ monkeypatch .setattr ("testcontainers.core.config.testcontainers_config.ryuk_disabled" , True )
26
+ with DockerContainer ("postgres" , auto_remove = False ).with_reuse () as container :
27
+ assert container ._reuse == True
28
+ id = container ._container .id
29
+ containers = DockerClient ().client .containers .list (all = True )
19
30
assert id in [container .id for container in containers ]
20
31
21
32
22
33
def test_docker_container_labels_hash ():
23
34
with DockerContainer ("hello-world" ).with_reuse () as container :
24
- assert container ._container .labels ["hash" ] == "fd35c55b0a6d03b7d569828d4bc4cc7f74b4312ded5936ae9bb7035798bb3628 "
35
+ assert container ._container .labels ["hash" ] == "505d1d913abe7f54b5a66202e8559a4f798038a204d39fe8b1577735ed632e32 "
25
36
26
37
27
38
def test_docker_client_find_container_by_hash_not_existing ():
0 commit comments