From 31fed211f61549b6a16be5b3b39eedad6c09a347 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 14 Oct 2018 00:36:32 +0300 Subject: [PATCH] test: use suffixes and prefixes in tmpdir names Signed-off-by: Ruslan Kuprieiev --- tests/basic_env.py | 10 +++++++++- tests/test_add.py | 3 +-- tests/test_cache.py | 3 +-- tests/test_data_cloud.py | 5 ++--- tests/test_repro.py | 5 ++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/basic_env.py b/tests/basic_env.py index 8c865a25d..978dba7d9 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -1,4 +1,5 @@ import os +import uuid import shutil import tempfile from git import Repo @@ -38,8 +39,15 @@ class TestDir(TestCase): with open(name, 'a') as f: f.write(contents) + @staticmethod + def mkdtemp(): + prefix = 'dvc-test.{}.'.format(os.getpid()) + suffix = '.{}'.format(uuid.uuid4()) + return tempfile.mkdtemp(prefix=prefix, suffix=suffix) + def setUp(self): - self._root_dir = tempfile.mkdtemp() + self._root_dir = TestDir.mkdtemp() + self._pushd(self._root_dir) self.create(self.FOO, self.FOO_CONTENTS) self.create(self.BAR, self.BAR_CONTENTS) diff --git a/tests/test_add.py b/tests/test_add.py index 9fa7436f5..8b9e1af2b 100644 --- a/tests/test_add.py +++ b/tests/test_add.py @@ -2,7 +2,6 @@ import os import stat import shutil import filecmp -import tempfile from dvc.main import main from dvc.utils import file_md5 @@ -132,7 +131,7 @@ class TestAddFileInDir(TestDvc): class TestAddExternalLocalFile(TestDvc): def test(self): - dname = tempfile.mkdtemp() + dname = TestDvc.mkdtemp() fname = os.path.join(dname, 'foo') shutil.copyfile(self.FOO, fname) diff --git a/tests/test_cache.py b/tests/test_cache.py index e73da66ff..1705eedd3 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,6 +1,5 @@ import os import shutil -import tempfile from dvc.cache import Cache from dvc.system import System @@ -52,7 +51,7 @@ class TestCacheLoadBadDirCache(TestDvc): class TestExternalCacheDir(TestDvc): def test(self): - cache_dir = tempfile.mkdtemp() + cache_dir = TestDvc.mkdtemp() ret = main(['config', 'cache.dir', cache_dir]) self.assertEqual(ret, 0) diff --git a/tests/test_data_cloud.py b/tests/test_data_cloud.py index 0e3737deb..f44051fed 100644 --- a/tests/test_data_cloud.py +++ b/tests/test_data_cloud.py @@ -6,7 +6,6 @@ import time import uuid import shutil import getpass -import tempfile import platform from dvc.main import main @@ -105,7 +104,7 @@ def _should_test_hdfs(): def get_local_storagepath(): - return tempfile.mkdtemp() + return TestDvc.mkdtemp() def get_local_url(): @@ -164,7 +163,7 @@ class TestDataCloud(TestDvc): clist = [('s3://', RemoteS3), ('gs://', RemoteGS), ('ssh://user@localhost:/', RemoteSSH), - (tempfile.mkdtemp(), RemoteLOCAL)] + (TestDvc.mkdtemp(), RemoteLOCAL)] if _should_test_azure(): clist.append(('azure://ContainerName=', RemoteAzure)) diff --git a/tests/test_repro.py b/tests/test_repro.py index ba55a949a..70db0abdc 100644 --- a/tests/test_repro.py +++ b/tests/test_repro.py @@ -4,7 +4,6 @@ import stat import shutil import filecmp import getpass -import tempfile import posixpath from subprocess import Popen, PIPE @@ -655,7 +654,7 @@ class TestReproExternalSSH(TestReproExternalBase): @property def bucket(self): if not self._dir: - self._dir = tempfile.mkdtemp() + self._dir = TestDvc.mkdtemp() return '{}@127.0.0.1:{}'.format(getpass.getuser(), self._dir) def cmd(self, i, o): @@ -702,7 +701,7 @@ class TestReproExternalSSH(TestReproExternalBase): class TestReproExternalLOCAL(TestReproExternalBase): def setUp(self): super(TestReproExternalLOCAL, self).setUp() - self.tmpdir = tempfile.mkdtemp() + self.tmpdir = TestDvc.mkdtemp() def should_test(self): return True