2626from testing .fixtures import add_config_to_repo
2727from testing .fixtures import make_consuming_repo
2828from testing .fixtures import modify_config
29+ from testing .util import cmd_output_mocked_pre_commit_home
2930
3031
3132@pytest .yield_fixture
@@ -336,11 +337,9 @@ def test_non_ascii_hook_id(
336337):
337338 with cwd (repo_with_passing_hook ):
338339 install (Runner (repo_with_passing_hook ))
339- # Don't want to write to home directory
340- env = dict (os .environ , PRE_COMMIT_HOME = tempdir_factory .get ())
341- _ , stdout , _ = cmd_output (
340+ _ , stdout , _ = cmd_output_mocked_pre_commit_home (
342341 sys .executable , '-m' , 'pre_commit.main' , 'run' , '☃' ,
343- env = env , retcode = None ,
342+ retcode = None , tempdir_factory = tempdir_factory ,
344343 )
345344 assert 'UnicodeDecodeError' not in stdout
346345 # Doesn't actually happen, but a reasonable assertion
@@ -357,15 +356,13 @@ def test_stdout_write_bug_py26(
357356
358357 install (Runner (repo_with_failing_hook ))
359358
360- # Don't want to write to home directory
361- env = dict (os .environ , PRE_COMMIT_HOME = tempdir_factory .get ())
362359 # Have to use subprocess because pytest monkeypatches sys.stdout
363- _ , stdout , _ = cmd_output (
360+ _ , stdout , _ = cmd_output_mocked_pre_commit_home (
364361 'git' , 'commit' , '-m' , 'Commit!' ,
365362 # git commit puts pre-commit to stderr
366363 stderr = subprocess .STDOUT ,
367- env = env ,
368364 retcode = None ,
365+ tempdir_factory = tempdir_factory ,
369366 )
370367 assert 'UnicodeEncodeError' not in stdout
371368 # Doesn't actually happen, but a reasonable assertion
@@ -377,15 +374,13 @@ def test_hook_install_failure(mock_out_store_directory, tempdir_factory):
377374 with cwd (git_path ):
378375 install (Runner (git_path ))
379376
380- # Don't want to write to home directory
381- env = dict (os .environ , PRE_COMMIT_HOME = tempdir_factory .get ())
382- _ , stdout , _ = cmd_output (
377+ _ , stdout , _ = cmd_output_mocked_pre_commit_home (
383378 'git' , 'commit' , '-m' , 'Commit!' ,
384379 # git commit puts pre-commit to stderr
385380 stderr = subprocess .STDOUT ,
386- env = env ,
387381 retcode = None ,
388382 encoding = None ,
383+ tempdir_factory = tempdir_factory ,
389384 )
390385 assert b'UnicodeDecodeError' not in stdout
391386 # Doesn't actually happen, but a reasonable assertion
@@ -424,13 +419,11 @@ def test_lots_of_files(mock_out_store_directory, tempdir_factory):
424419 cmd_output ('bash' , '-c' , 'git add .' )
425420 install (Runner (git_path ))
426421
427- # Don't want to write to home directory
428- env = dict (os .environ , PRE_COMMIT_HOME = tempdir_factory .get ())
429- cmd_output (
422+ cmd_output_mocked_pre_commit_home (
430423 'git' , 'commit' , '-m' , 'Commit!' ,
431424 # git commit puts pre-commit to stderr
432425 stderr = subprocess .STDOUT ,
433- env = env ,
426+ tempdir_factory = tempdir_factory ,
434427 )
435428
436429
@@ -609,13 +602,11 @@ def test_files_running_subdir(
609602 cmd_output ('git' , 'add' , 'subdir/foo.py' )
610603
611604 with cwd ('subdir' ):
612- # Don't want to write to home directory
613- env = dict (os .environ , PRE_COMMIT_HOME = tempdir_factory .get ())
614605 # Use subprocess to demonstrate behaviour in main
615- _ , stdout , _ = cmd_output (
606+ _ , stdout , _ = cmd_output_mocked_pre_commit_home (
616607 sys .executable , '-m' , 'pre_commit.main' , 'run' , '-v' ,
617608 # Files relative to where we are (#339)
618609 '--files' , 'foo.py' ,
619- env = env ,
610+ tempdir_factory = tempdir_factory ,
620611 )
621612 assert 'subdir/foo.py' .replace ('/' , os .sep ) in stdout
0 commit comments