def test_successful_default_refresh_invalidates_cached_version_info(self):
        """Refreshing updates version after a filesystem change adds a git command."""
        # The key assertion here is the last. The others mainly verify the test itself.
        with contextlib.ExitStack() as stack:
            stack.enter_context(_rollback_refresh())

            path1 = Path(stack.enter_context(_fake_git(11, 111, 1)))
            path2 = Path(stack.enter_context(_fake_git(22, 222, 2)))

            new_path_var = f"{path1.parent}{os.pathsep}{path2.parent}"
            stack.enter_context(mock.patch.dict(os.environ, {"PATH": new_path_var}))
            stack.enter_context(_patch_out_env("GIT_PYTHON_GIT_EXECUTABLE"))

            if sys.platform == "win32":
                # On Windows, use a shell so "git" finds "git.cmd". The correct and safe
                # ways to do this straightforwardly are to set GIT_PYTHON_GIT_EXECUTABLE
                # to git.cmd in the environment, or call git.refresh with the command's
                # full path. See the Git.USE_SHELL docstring for deprecation details.
                # But this tests a "default" scenario where neither is done. The
                # approach used here, setting USE_SHELL to True so PATHEXT is honored,
                # should not be used in production code (nor even in most test cases).
                stack.enter_context(mock.patch.object(Git, "USE_SHELL", True))

            new_git = Git()
            _rename_with_stem(path2, "git")  # "Install" git, "late" in the PATH.
            refresh()
            self.assertEqual(new_git.version_info, (22, 222, 2), 'before "downgrade"')
            _rename_with_stem(path1, "git")  # "Install" another, higher priority.
            self.assertEqual(new_git.version_info, (22, 222, 2), "stale version")
            refresh()
            self.assertEqual(new_git.version_info, (11, 111, 1), "fresh version")
Refreshing updates version after a filesystem change adds a git command.
test/test_git.py