Skip to content

Commit 272c1f8

Browse files
committed
support specifying location of temp folders
TestWithBinds was failing when shared folders are used because /tmp was not shared from OS X to my VM. This fix allows the location of the temp folders to be changed via: TMPDIR=$(pwd) env/bin/python setup.py test This also properly cleans up temp folders which were sticking around before.
1 parent b5e75c4 commit 272c1f8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/integration_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import json
1818
import io
1919
import os
20+
import shutil
2021
import signal
2122
import tempfile
2223
import unittest
@@ -31,11 +32,13 @@
3132
class BaseTestCase(unittest.TestCase):
3233
tmp_imgs = []
3334
tmp_containers = []
35+
tmp_folders = []
3436

3537
def setUp(self):
3638
self.client = docker.Client(timeout=5)
3739
self.tmp_imgs = []
3840
self.tmp_containers = []
41+
self.tmp_folders = []
3942

4043
def tearDown(self):
4144
for img in self.tmp_imgs:
@@ -49,6 +52,8 @@ def tearDown(self):
4952
self.client.remove_container(container)
5053
except docker.errors.APIError:
5154
pass
55+
for folder in self.tmp_folders:
56+
shutil.rmtree(folder)
5257

5358
#########################
5459
# INFORMATION TESTS #
@@ -138,7 +143,8 @@ def runTest(self):
138143
class TestCreateContainerWithBinds(BaseTestCase):
139144
def runTest(self):
140145
mount_dest = '/mnt'
141-
mount_origin = '/tmp'
146+
mount_origin = tempfile.mkdtemp()
147+
self.tmp_folders.append(mount_origin)
142148

143149
filename = 'shared.txt'
144150
shared_file = os.path.join(mount_origin, filename)
@@ -850,6 +856,7 @@ def runTest(self):
850856
class TestLoadConfig(BaseTestCase):
851857
def runTest(self):
852858
folder = tempfile.mkdtemp()
859+
self.tmp_folders.append(folder)
853860
f = open(os.path.join(folder, '.dockercfg'), 'w')
854861
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
855862
f.write('auth = {0}\n'.format(auth_))
@@ -867,6 +874,7 @@ def runTest(self):
867874
class TestLoadJSONConfig(BaseTestCase):
868875
def runTest(self):
869876
folder = tempfile.mkdtemp()
877+
self.tmp_folders.append(folder)
870878
f = open(os.path.join(folder, '.dockercfg'), 'w')
871879
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
872880
email_ = '[email protected]'

0 commit comments

Comments
 (0)