Skip to content

Commit 94aa9a8

Browse files
committed
Update tests to properly dispose of client instances in tearDown
Signed-off-by: Joffrey F <[email protected]>
1 parent 1df021e commit 94aa9a8

File tree

4 files changed

+48
-46
lines changed

4 files changed

+48
-46
lines changed

tests/integration/api_network_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
class TestNetworks(BaseAPIIntegrationTest):
1010
def tearDown(self):
11-
super(TestNetworks, self).tearDown()
1211
self.client.leave_swarm(force=True)
12+
super(TestNetworks, self).tearDown()
1313

1414
def create_network(self, *args, **kwargs):
1515
net_name = random_name()

tests/integration/api_plugin_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import docker
44
import pytest
55

6-
from .base import BaseAPIIntegrationTest, TEST_API_VERSION
6+
from .base import BaseAPIIntegrationTest
77
from ..helpers import requires_api_version
88

99
SSHFS = 'vieux/sshfs:latest'
@@ -13,27 +13,27 @@
1313
class PluginTest(BaseAPIIntegrationTest):
1414
@classmethod
1515
def teardown_class(cls):
16-
c = docker.APIClient(
17-
version=TEST_API_VERSION, timeout=60,
18-
**docker.utils.kwargs_from_env()
19-
)
16+
client = cls.get_client_instance()
2017
try:
21-
c.remove_plugin(SSHFS, force=True)
18+
client.remove_plugin(SSHFS, force=True)
2219
except docker.errors.APIError:
2320
pass
2421

2522
def teardown_method(self, method):
23+
client = self.get_client_instance()
2624
try:
27-
self.client.disable_plugin(SSHFS)
25+
client.disable_plugin(SSHFS)
2826
except docker.errors.APIError:
2927
pass
3028

3129
for p in self.tmp_plugins:
3230
try:
33-
self.client.remove_plugin(p, force=True)
31+
client.remove_plugin(p, force=True)
3432
except docker.errors.APIError:
3533
pass
3634

35+
client.close()
36+
3737
def ensure_plugin_installed(self, plugin_name):
3838
try:
3939
return self.client.inspect_plugin(plugin_name)

tests/integration/api_swarm_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ def setUp(self):
1313
self._unlock_key = None
1414

1515
def tearDown(self):
16-
super(SwarmTest, self).tearDown()
1716
try:
1817
if self._unlock_key:
1918
self.client.unlock_swarm(self._unlock_key)
2019
except docker.errors.APIError:
2120
pass
22-
2321
force_leave_swarm(self.client)
22+
super(SwarmTest, self).tearDown()
2423

2524
@requires_api_version('1.24')
2625
def test_init_swarm_simple(self):

tests/integration/base.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,44 @@ def setUp(self):
2929

3030
def tearDown(self):
3131
client = docker.from_env(version=TEST_API_VERSION)
32-
for img in self.tmp_imgs:
33-
try:
34-
client.api.remove_image(img)
35-
except docker.errors.APIError:
36-
pass
37-
for container in self.tmp_containers:
38-
try:
39-
client.api.remove_container(container, force=True, v=True)
40-
except docker.errors.APIError:
41-
pass
42-
for network in self.tmp_networks:
43-
try:
44-
client.api.remove_network(network)
45-
except docker.errors.APIError:
46-
pass
47-
for volume in self.tmp_volumes:
48-
try:
49-
client.api.remove_volume(volume)
50-
except docker.errors.APIError:
51-
pass
52-
53-
for secret in self.tmp_secrets:
54-
try:
55-
client.api.remove_secret(secret)
56-
except docker.errors.APIError:
57-
pass
58-
59-
for config in self.tmp_configs:
60-
try:
61-
client.api.remove_config(config)
62-
except docker.errors.APIError:
63-
pass
64-
65-
for folder in self.tmp_folders:
66-
shutil.rmtree(folder)
32+
try:
33+
for img in self.tmp_imgs:
34+
try:
35+
client.api.remove_image(img)
36+
except docker.errors.APIError:
37+
pass
38+
for container in self.tmp_containers:
39+
try:
40+
client.api.remove_container(container, force=True, v=True)
41+
except docker.errors.APIError:
42+
pass
43+
for network in self.tmp_networks:
44+
try:
45+
client.api.remove_network(network)
46+
except docker.errors.APIError:
47+
pass
48+
for volume in self.tmp_volumes:
49+
try:
50+
client.api.remove_volume(volume)
51+
except docker.errors.APIError:
52+
pass
53+
54+
for secret in self.tmp_secrets:
55+
try:
56+
client.api.remove_secret(secret)
57+
except docker.errors.APIError:
58+
pass
59+
60+
for config in self.tmp_configs:
61+
try:
62+
client.api.remove_config(config)
63+
except docker.errors.APIError:
64+
pass
65+
66+
for folder in self.tmp_folders:
67+
shutil.rmtree(folder)
68+
finally:
69+
client.close()
6770

6871

6972
class BaseAPIIntegrationTest(BaseIntegrationTest):

0 commit comments

Comments
 (0)