Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def cmd_output_mocked_pre_commit_home(*args, **kwargs):
reason='swift isn\'t installed or can\'t be found',
)

skipif_cant_run_go = pytest.mark.skipif(
parse_shebang.find_executable('go') is None,
reason='go isn\'t installed or can\'t be found',
)

skipif_cant_run_bash = pytest.mark.skipif(
parse_shebang.find_executable('bash') is None,
reason='bash isn\'t installed or can\'t be found',
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without bash, most of the testsuite is useless -- pre-commit tests lots of the framework functionality with script hooks as they are fast. I don't think I can accept a PR which adds skips for bash. As bash is necessarily installed on all the platforms we support (it's necessary for git itself to function) this also seems inappropriate.


xfailif_windows_no_ruby = pytest.mark.xfail(
os.name == 'nt',
reason='Ruby support not yet implemented on windows.',
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def get(self):
yield TmpdirFactory()


@pytest.fixture()
def setup_git(monkeypatch, tmpdir):
# we should not use user configuration
monkeypatch.setenv('HOME', tmpdir)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had the same situation in pre-commit-hooks and I think this is the wrong solution as it has the potential to hide problems with different configurations. We instead opted to pass --no-gpg-sign to any git commits under test: pre-commit/pre-commit-hooks#121

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixture also doesn't scale (adding it to literally every test) -- perhaps instead an autouse fixture would have been more appropriate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see


@pytest.yield_fixture
def in_tmpdir(tempdir_factory):
path = tempdir_factory.get()
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/git_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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', '.')
Expand Down
Loading