From f5bb6e06fd0af3382a3b6f5103606752c913fcaf Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 4 May 2015 22:56:48 +0100 Subject: [PATCH] Isolate tests from user/system git configuration Prevent user or system configuration from impacting the output of git commands through custom configuration options. Example is enabling of "branch.autosetuprebase=always" will result a different message being outputted by git when creating branches causing some tests to fail when attempting to match against the expected output. Change-Id: Ic6526217b598abfef0a272bc7cd1852c5821163a --- git_review/tests/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git_review/tests/__init__.py b/git_review/tests/__init__.py index dc2d894..1aa53ae 100644 --- a/git_review/tests/__init__.py +++ b/git_review/tests/__init__.py @@ -173,6 +173,18 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers): # ensure user proxy conf doesn't interfere with tests os.environ['no_proxy'] = os.environ['NO_PROXY'] = '*' + # isolate tests from user and system git configuration + self.home_dir = self._dir('site', 'tmp', 'home') + self.xdg_config_dir = self._dir('home', '.xdgconfig') + os.environ['HOME'] = self.home_dir + os.environ['XDG_CONFIG_HOME'] = self.xdg_config_dir + os.environ['GIT_CONFIG_NOSYSTEM'] = "1" + if not os.path.exists(self.home_dir): + os.mkdir(self.home_dir) + if not os.path.exists(self.xdg_config_dir): + os.mkdir(self.xdg_config_dir) + self.addCleanup(shutil.rmtree, self.home_dir) + # prepare repository for the testing self._run_git('clone', self.project_uri) utils.write_to_file(self._dir('test', 'test_file.txt'),