Skip to content

Commit b3fc30e

Browse files
committed
Re-refresh to restore state after refresh tests
For gitpython-developers#1811. This is the simple way to do it. This relies on git.refresh working when called when no arguments, so if that ever breaks, then it may be difficult or inefficient to investigate. But this is simpler than any alternatives that are equally or more robust. This is already better than the previous incomplete way that only restored Git.GIT_PYTHON_GIT_EXECUTABLE (and nothing in FetchInfo). Furthermore, because the tests already depend to a large extent on git.refreh working when called with no arguments, as otherwise the initial refresh may not have set Git.GIT_PYTHON_GIT_EXECUTABLE usably, it might not be worthwhile to explore other approaches.
1 parent 5ad7cb2 commit b3fc30e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Diff for: test/test_git.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ def _patch_out_env(name):
4545

4646

4747
@contextlib.contextmanager
48-
def _restore_git_executable():
48+
def _rollback_refresh():
4949
old_git_executable = Git.GIT_PYTHON_GIT_EXECUTABLE
5050
try:
51-
yield old_git_executable # Let test code run that may rebind the attribute.
51+
yield old_git_executable # Let test code run that may mutate class state.
5252
finally:
53-
Git.GIT_PYTHON_GIT_EXECUTABLE = old_git_executable
53+
refresh()
5454

5555

5656
@ddt.ddt
@@ -319,7 +319,7 @@ def test_refresh_bad_absolute_git_path(self):
319319
absolute_path = str(Path("yada").absolute())
320320
expected_pattern = rf"\n[ \t]*cmdline: {re.escape(absolute_path)}\Z"
321321

322-
with _restore_git_executable() as old_git_executable:
322+
with _rollback_refresh() as old_git_executable:
323323
with self.assertRaisesRegex(GitCommandNotFound, expected_pattern):
324324
refresh(absolute_path)
325325
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, old_git_executable)
@@ -328,15 +328,15 @@ def test_refresh_bad_relative_git_path(self):
328328
absolute_path = str(Path("yada").absolute())
329329
expected_pattern = rf"\n[ \t]*cmdline: {re.escape(absolute_path)}\Z"
330330

331-
with _restore_git_executable() as old_git_executable:
331+
with _rollback_refresh() as old_git_executable:
332332
with self.assertRaisesRegex(GitCommandNotFound, expected_pattern):
333333
refresh("yada")
334334
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, old_git_executable)
335335

336336
def test_refresh_good_absolute_git_path(self):
337337
absolute_path = shutil.which("git")
338338

339-
with _restore_git_executable():
339+
with _rollback_refresh():
340340
refresh(absolute_path)
341341
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, absolute_path)
342342

@@ -345,7 +345,7 @@ def test_refresh_good_relative_git_path(self):
345345
dirname, basename = osp.split(absolute_path)
346346

347347
with cwd(dirname):
348-
with _restore_git_executable():
348+
with _rollback_refresh():
349349
refresh(basename)
350350
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, absolute_path)
351351

0 commit comments

Comments
 (0)