Skip to content

Commit ab1f90a

Browse files
committed
Cleanup containers during the tests
This fix tries to clean up the containers during the tests so that no pre-existing volumes left in docker integration tests. This fix adds `-v` when removing containers, and makes sure containers launched in non-daemon mode are removed. This fix is realted to moby PR 36292 Signed-off-by: Yong Tang <[email protected]>
1 parent d41e060 commit ab1f90a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tests/integration/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def tearDown(self):
3636
pass
3737
for container in self.tmp_containers:
3838
try:
39-
client.api.remove_container(container, force=True)
39+
client.api.remove_container(container, force=True, v=True)
4040
except docker.errors.APIError:
4141
pass
4242
for network in self.tmp_networks:

tests/integration/models_containers_test.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ def test_run_with_volume(self):
4747
self.tmp_containers.append(container.id)
4848
container.wait()
4949

50+
name = "container_volume_test"
5051
out = client.containers.run(
5152
"alpine", "cat /insidecontainer/test",
52-
volumes=["%s:/insidecontainer" % path]
53+
volumes=["%s:/insidecontainer" % path],
54+
name=name
5355
)
56+
self.tmp_containers.append(name)
5457
assert out == b'hello\n'
5558

5659
def test_run_with_named_volume(self):
@@ -66,10 +69,13 @@ def test_run_with_named_volume(self):
6669
self.tmp_containers.append(container.id)
6770
container.wait()
6871

72+
name = "container_volume_test"
6973
out = client.containers.run(
7074
"alpine", "cat /insidecontainer/test",
71-
volumes=["somevolume:/insidecontainer"]
75+
volumes=["somevolume:/insidecontainer"],
76+
name=name
7277
)
78+
self.tmp_containers.append(name)
7379
assert out == b'hello\n'
7480

7581
def test_run_with_network(self):

0 commit comments

Comments
 (0)