mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 02:21:46 +04:00
fix(tests): ensure tests using _path_without_us() are skipped if pre-commit is installed system-wide
This commit is contained in:
parent
78ccfbf863
commit
e7fe7468dd
2 changed files with 11 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ from testing.auto_namedtuple import auto_namedtuple
|
||||||
|
|
||||||
|
|
||||||
TESTING_DIR = os.path.abspath(os.path.dirname(__file__))
|
TESTING_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
SYSTEM_PATH = {'PATH': '/usr/bin:/usr/local/bin'}
|
||||||
|
|
||||||
|
|
||||||
def docker_is_running() -> bool: # pragma: win32 no cover
|
def docker_is_running() -> bool: # pragma: win32 no cover
|
||||||
|
|
@ -84,6 +85,10 @@ skipif_cant_run_swift = pytest.mark.skipif(
|
||||||
parse_shebang.find_executable('swift') is None,
|
parse_shebang.find_executable('swift') is None,
|
||||||
reason="swift isn't installed or can't be found",
|
reason="swift isn't installed or can't be found",
|
||||||
)
|
)
|
||||||
|
skipif_pre_commit_system_install = pytest.mark.skipif(
|
||||||
|
bool(parse_shebang.find_executable('pre-commit', SYSTEM_PATH)),
|
||||||
|
reason='pre-commit is installed system-wide, this test will fail',
|
||||||
|
)
|
||||||
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ from testing.fixtures import write_config
|
||||||
from testing.util import cmd_output_mocked_pre_commit_home
|
from testing.util import cmd_output_mocked_pre_commit_home
|
||||||
from testing.util import cwd
|
from testing.util import cwd
|
||||||
from testing.util import git_commit
|
from testing.util import git_commit
|
||||||
|
from testing.util import skipif_pre_commit_system_install
|
||||||
|
|
||||||
|
|
||||||
def test_is_not_script():
|
def test_is_not_script():
|
||||||
|
|
@ -255,6 +256,9 @@ def test_install_idempotent(tempdir_factory, store):
|
||||||
|
|
||||||
def _path_without_us():
|
def _path_without_us():
|
||||||
# Choose a path which *probably* doesn't include us
|
# Choose a path which *probably* doesn't include us
|
||||||
|
# WARNING: on system with pre-commit installer system-wide,
|
||||||
|
# this will break the test because /usr/bin will be removed from $PATH
|
||||||
|
# decorate the test using this with @skipif_pre_commit_system_install
|
||||||
env = dict(os.environ)
|
env = dict(os.environ)
|
||||||
exe = find_executable('pre-commit', _environ=env)
|
exe = find_executable('pre-commit', _environ=env)
|
||||||
while exe:
|
while exe:
|
||||||
|
|
@ -270,6 +274,7 @@ def _path_without_us():
|
||||||
return env['PATH']
|
return env['PATH']
|
||||||
|
|
||||||
|
|
||||||
|
@skipif_pre_commit_system_install
|
||||||
def test_environment_not_sourced(tempdir_factory, store):
|
def test_environment_not_sourced(tempdir_factory, store):
|
||||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
|
|
@ -528,6 +533,7 @@ def test_install_hooks_command(tempdir_factory, store):
|
||||||
PRE_INSTALLED.assert_matches(output)
|
PRE_INSTALLED.assert_matches(output)
|
||||||
|
|
||||||
|
|
||||||
|
@skipif_pre_commit_system_install
|
||||||
def test_installed_from_venv(tempdir_factory, store):
|
def test_installed_from_venv(tempdir_factory, store):
|
||||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
with cwd(path):
|
with cwd(path):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue