下面是我的.pre-commit-config。
# See https://pre-commit.com/hooks.html for more hooks
fail_fast: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: local
hooks:
- id: isort
name: isort
entry: isort
language: python
types: [python]
- repo: local
hooks:
- id: black
name: black
entry: black
language: python
types: [python]
- repo: local
hooks:
- id: pytest-check
name: pytest-check
#entry: pytest tests/test_file2.py
entry: pytest
language: python
#args: [--maxfail=1]
#stages: [post-commit]
pass_filenames: false
always_run: false
我希望实现如下两件事。
- 有时候,开发人员也会修改业务逻辑和测试用例,但由于某些原因,这些修改会失败。而且,如果测试用例持续失败,那么就有丢失代码的风险,因为在通过所有检查之前,预提交不允许提交更改。因此,即使测试用例失败,我们也应该总是希望能够提交到特性分支。注意请记住,我想为实现上述场景pytest-check
- 根据我当前的pre-commit-config配置。Yaml文件,它执行完整的测试套装。但是我想为特定的测试用例文件执行。
通知你。我已经探索了一种绕过预提交的方法,但它适用于.pre-commit-config中提到的所有钩子。yaml文件。
我们如何实现这两种情况?请提出您的意见?
将您的测试放入一个shell脚本中,该脚本实际上执行
pytest tests/test_file2.py (or whatever you are doing now)
true
最后一个命令也可以是exit 0
,或者其他任何成功退出的命令。)这样测试就可以运行了,虽然有副作用和输出,但是git总是将它们视为成功的。