@@ -90,7 +90,9 @@ def test_install_hooks_directory_not_present(tempdir_factory):
9090
9191
9292@xfailif_no_symlink
93- def test_install_hooks_dead_symlink (tempdir_factory ):
93+ def test_install_hooks_dead_symlink (
94+ tempdir_factory ,
95+ ): # pragma: no cover (non-windows)
9496 path = git_dir (tempdir_factory )
9597 os .symlink ('/fake/baz' , os .path .join (path , '.git' , 'hooks' , 'pre-commit' ))
9698 runner = Runner (path )
@@ -175,6 +177,14 @@ def test_install_idempotent(tempdir_factory):
175177 assert NORMAL_PRE_COMMIT_RUN .match (output )
176178
177179
180+ def _path_without_us ():
181+ # Choose a path which *probably* doesn't include us
182+ return os .pathsep .join ([
183+ x for x in os .environ ['PATH' ].split (os .pathsep )
184+ if x .lower () != os .path .dirname (sys .executable ).lower ()
185+ ])
186+
187+
178188def test_environment_not_sourced (tempdir_factory ):
179189 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
180190 with cwd (path ):
@@ -193,7 +203,7 @@ def test_environment_not_sourced(tempdir_factory):
193203 )
194204 ret , stdout , stderr = cmd_output (
195205 'git' , 'commit' , '--allow-empty' , '-m' , 'foo' ,
196- env = {'HOME' : homedir },
206+ env = {'HOME' : homedir , 'PATH' : _path_without_us () },
197207 retcode = None ,
198208 )
199209 assert ret == 1
@@ -422,6 +432,7 @@ def test_installed_from_venv(tempdir_factory):
422432 tempdir_factory ,
423433 env_base = {
424434 'HOME' : os .path .expanduser ('~' ),
435+ 'PATH' : _path_without_us (),
425436 'TERM' : os .environ .get ('TERM' , '' ),
426437 # Windows needs this to import `random`
427438 'SYSTEMROOT' : os .environ .get ('SYSTEMROOT' , '' ),
0 commit comments