From 5b472b30eb5c7006317edf6fe3feb88e13755254 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Fri, 27 Oct 2017 11:01:52 +0100 Subject: [PATCH] change the HOME for git commands to avoid using the user git configuration --- tests/conftest.py | 9 +++++++-- tests/git_test.py | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 36743d88..56988b14 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,6 +39,11 @@ def tempdir_factory(tmpdir): yield TmpdirFactory() +@pytest.fixture() +def setup_git(monkeypatch, tmpdir): + # we should not use user configuration + monkeypatch.setenv('HOME', tmpdir) + @pytest.yield_fixture def in_tmpdir(tempdir_factory): path = tempdir_factory.get() @@ -67,7 +72,7 @@ def _make_conflict(): @pytest.yield_fixture -def in_merge_conflict(tempdir_factory): +def in_merge_conflict(tempdir_factory, setup_git): path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') with cwd(path): open('dummy', 'a').close() @@ -82,7 +87,7 @@ def in_merge_conflict(tempdir_factory): @pytest.yield_fixture -def in_conflicting_submodule(tempdir_factory): +def in_conflicting_submodule(tempdir_factory, setup_git): git_dir_1 = git_dir(tempdir_factory) git_dir_2 = git_dir(tempdir_factory) with cwd(git_dir_2): diff --git a/tests/git_test.py b/tests/git_test.py index 8f80dcad..637e2fc8 100644 --- a/tests/git_test.py +++ b/tests/git_test.py @@ -34,7 +34,7 @@ def test_get_root_not_git_dir(tempdir_factory): git.get_root() -def test_get_staged_files_deleted(tempdir_factory): +def test_get_staged_files_deleted(tempdir_factory, setup_git): path = git_dir(tempdir_factory) with cwd(path): open('test', 'a').close() @@ -114,7 +114,7 @@ def test_parse_merge_msg_for_conflicts(input, expected_output): assert ret == expected_output -def test_get_changed_files(in_tmpdir): +def test_get_changed_files(in_tmpdir, setup_git): cmd_output('git', 'init', '.') cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit') open('a.txt', 'a').close() @@ -143,7 +143,7 @@ def test_zsplit(s, expected): @pytest.fixture -def non_ascii_repo(tmpdir): +def non_ascii_repo(tmpdir, setup_git): repo = tmpdir.join('repo').ensure_dir() with repo.as_cwd(): cmd_output('git', 'init', '.')