Merge pull request #1045 from pre-commit/fix_test_pre_commit_on_path

Fix test_environment_not_sourced when pre-commit is installed globally
This commit is contained in:
Anthony Sottile 2019-05-26 19:11:57 -07:00 committed by GitHub
commit 099f521b7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -10,7 +10,7 @@ resources:
type: github type: github
endpoint: github endpoint: github
name: asottile/azure-pipeline-templates name: asottile/azure-pipeline-templates
ref: refs/tags/v0.0.13 ref: refs/tags/v0.0.14
jobs: jobs:
- template: job--pre-commit.yml@asottile - template: job--pre-commit.yml@asottile

View file

@ -18,6 +18,7 @@ from pre_commit.commands.install_uninstall import is_our_script
from pre_commit.commands.install_uninstall import PRIOR_HASHES from pre_commit.commands.install_uninstall import PRIOR_HASHES
from pre_commit.commands.install_uninstall import shebang from pre_commit.commands.install_uninstall import shebang
from pre_commit.commands.install_uninstall import uninstall from pre_commit.commands.install_uninstall import uninstall
from pre_commit.parse_shebang import find_executable
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.util import make_executable from pre_commit.util import make_executable
from pre_commit.util import mkdirp from pre_commit.util import mkdirp
@ -234,10 +235,16 @@ 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
return os.pathsep.join([ env = dict(os.environ)
x for x in os.environ['PATH'].split(os.pathsep) exe = find_executable('pre-commit', _environ=env)
if x.lower() != os.path.dirname(sys.executable).lower() while exe:
]) parts = env['PATH'].split(os.pathsep)
after = [x for x in parts if x.lower() != os.path.dirname(exe).lower()]
if parts == after:
raise AssertionError(exe, parts)
env['PATH'] = os.pathsep.join(after)
exe = find_executable('pre-commit', _environ=env)
return env['PATH']
def test_environment_not_sourced(tempdir_factory, store): def test_environment_not_sourced(tempdir_factory, store):