执行pre-commit run --all-files遇InvalidManifestError,求pytest钩子解决方案
解决pre-commit执行pytest时的InvalidManifestError问题
问题原因
你直接将repo指向pytest-dev/pytest仓库,但这个仓库没有提供pre-commit所需的.pre-commit-hooks.yaml配置文件,导致pre-commit初始化环境时找不到hook定义,抛出InvalidManifestError。
解决办法
方案1:使用pre-commit官方hooks仓库的pytest hook
修改你的.pre-commit-config.yaml,替换为维护完善的pre-commit hooks仓库:
- repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 # 可替换为该仓库的最新版本号 hooks: - id: pytest
方案2:自定义本地pytest hook(更灵活)
如果需要自定义pytest的执行参数,可使用本地hook配置:
- repo: local hooks: - id: pytest name: pytest entry: pytest # 可添加参数,比如pytest -xvs language: system types: [python] pass_filenames: false # 若需要检查所有文件,设置为false;若仅检查变更文件,可设为true并调整types
后续操作
- 清理pre-commit缓存,避免残留的错误仓库信息:
pre-commit clean
- 重新执行命令:
pre-commit run --all-files
内容的提问来源于stack exchange,提问作者MUTHARASU ARCHUNAN
相关产品推荐
相关产品推荐

