summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiQiang Fan <aji.zqfan@gmail.com>2015-12-16 05:37:33 +0800
committerZhiQiang Fan <aji.zqfan@gmail.com>2015-12-16 05:46:18 +0800
commit6ca7d15f4c0ba6499dbf8999d8d501505ccd4dfe (patch)
treedb121679ea03a69cf8913ef2b92a571340896423
parente46a46ba90741987f1147afc56876e3d0d27e8a2 (diff)
downloadoslo-utils-6ca7d15f4c0ba6499dbf8999d8d501505ccd4dfe.tar.gz
fix fileutils ut code random failure
test_file_with_not_existing_path_and_not_default_suffix and test_file_with_not_existing_path have created tempory file which share same directory tree, when run test code parallel, one might fail because the other one has cleaned that directory. This patch replaces constant directory name with random name. Change-Id: If663f81bd2f09b8d07fb371bd27237044f17ee6f Closes-Bug: #1526323
-rw-r--r--oslo_utils/tests/test_fileutils.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/oslo_utils/tests/test_fileutils.py b/oslo_utils/tests/test_fileutils.py
index 59f1141..a16e28e 100644
--- a/oslo_utils/tests/test_fileutils.py
+++ b/oslo_utils/tests/test_fileutils.py
@@ -18,6 +18,7 @@ import os
import shutil
import stat
import tempfile
+import uuid
from oslotest import base as test_base
import six
@@ -139,7 +140,8 @@ class WriteToTempfileTestCase(test_base.BaseTestCase):
self.check_file_content(res)
def test_file_with_not_existing_path(self):
- path = '/tmp/testing/test1'
+ random_dir = uuid.uuid4().hex
+ path = '/tmp/%s/test1' % random_dir
res = fileutils.write_to_tempfile(self.content, path=path)
self.assertTrue(os.path.exists(res))
(basepath, tmpfile) = os.path.split(res)
@@ -147,7 +149,7 @@ class WriteToTempfileTestCase(test_base.BaseTestCase):
self.assertTrue(tmpfile.startswith('tmp'))
self.check_file_content(res)
- shutil.rmtree('/tmp/testing')
+ shutil.rmtree('/tmp/' + random_dir)
def test_file_with_not_default_suffix(self):
suffix = '.conf'
@@ -163,7 +165,8 @@ class WriteToTempfileTestCase(test_base.BaseTestCase):
def test_file_with_not_existing_path_and_not_default_suffix(self):
suffix = '.txt'
- path = '/tmp/testing/test2'
+ random_dir = uuid.uuid4().hex
+ path = '/tmp/%s/test2' % random_dir
res = fileutils.write_to_tempfile(self.content,
path=path,
suffix=suffix)
@@ -174,7 +177,7 @@ class WriteToTempfileTestCase(test_base.BaseTestCase):
self.assertTrue(tmpfile.endswith(suffix))
self.check_file_content(res)
- shutil.rmtree('/tmp/testing')
+ shutil.rmtree('/tmp/' + random_dir)
def test_file_with_not_default_prefix(self):
prefix = 'test'