Browse Source

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
tags/1.0.0
Darragh Bailey 4 years ago
parent
commit
f5bb6e06fd
1 changed files with 12 additions and 0 deletions
  1. 12
    0
      git_review/tests/__init__.py

+ 12
- 0
git_review/tests/__init__.py View File

@@ -173,6 +173,18 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
173 173
         # ensure user proxy conf doesn't interfere with tests
174 174
         os.environ['no_proxy'] = os.environ['NO_PROXY'] = '*'
175 175
 
176
+        # isolate tests from user and system git configuration
177
+        self.home_dir = self._dir('site', 'tmp', 'home')
178
+        self.xdg_config_dir = self._dir('home', '.xdgconfig')
179
+        os.environ['HOME'] = self.home_dir
180
+        os.environ['XDG_CONFIG_HOME'] = self.xdg_config_dir
181
+        os.environ['GIT_CONFIG_NOSYSTEM'] = "1"
182
+        if not os.path.exists(self.home_dir):
183
+            os.mkdir(self.home_dir)
184
+        if not os.path.exists(self.xdg_config_dir):
185
+            os.mkdir(self.xdg_config_dir)
186
+        self.addCleanup(shutil.rmtree, self.home_dir)
187
+
176 188
         # prepare repository for the testing
177 189
         self._run_git('clone', self.project_uri)
178 190
         utils.write_to_file(self._dir('test', 'test_file.txt'),

Loading…
Cancel
Save