From a4522b99327afae1410672559bbda04661695ae7 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Mon, 11 Feb 2019 08:37:28 +0100 Subject: [PATCH] test_repo_utils: fix shared temporary directory Signed-off-by: Kyr --- teuthology/test/test_repo_utils.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/teuthology/test/test_repo_utils.py b/teuthology/test/test_repo_utils.py index 41542e0b0..f49bfb476 100644 --- a/teuthology/test/test_repo_utils.py +++ b/teuthology/test/test_repo_utils.py @@ -4,6 +4,7 @@ import os.path from pytest import raises, mark import shutil import subprocess +import tempfile from ..exceptions import BranchNotFoundError from .. import repo_utils @@ -12,20 +13,21 @@ repo_utils.log.setLevel(logging.WARNING) class TestRepoUtils(object): - src_path = '/tmp/empty_src' - # online_repo_url = 'https://github.com/ceph/teuthology.git' - # online_repo_url = 'git://ceph.newdream.net/git/teuthology.git' - online_repo_url = 'https://github.com/ceph/empty.git' - offline_repo_url = 'file://' + src_path - repo_url = None - dest_path = '/tmp/empty_dest' @classmethod def setup_class(cls): + cls.temp_path = tempfile.mkdtemp(prefix='test_repo-') + cls.dest_path = cls.temp_path + '/empty_dest' + cls.src_path = cls.temp_path + '/empty_src' + if 'TEST_ONLINE' in os.environ: - cls.repo_url = cls.online_repo_url + cls.repo_url = 'https://github.com/ceph/empty.git' else: - cls.repo_url = cls.offline_repo_url + cls.repo_url = 'file://' + cls.src_path + + @classmethod + def teardown_class(cls): + shutil.rmtree(cls.temp_path) def setup_method(self, method): assert not os.path.exists(self.dest_path) @@ -67,7 +69,7 @@ class TestRepoUtils(object): assert not os.path.exists(self.dest_path) def test_fetch_no_repo(self): - fake_dest_path = '/tmp/not_a_repo' + fake_dest_path = self.temp_path + '/not_a_repo' assert not os.path.exists(fake_dest_path) with raises(OSError): repo_utils.fetch(fake_dest_path) @@ -79,7 +81,7 @@ class TestRepoUtils(object): assert os.path.exists(self.dest_path) def test_fetch_branch_no_repo(self): - fake_dest_path = '/tmp/not_a_repo' + fake_dest_path = self.temp_path + '/not_a_repo' assert not os.path.exists(fake_dest_path) with raises(OSError): repo_utils.fetch_branch(fake_dest_path, 'master') -- 2.47.3