1

I've a pre-commit, and I want to add a pre-push hook within. So, I want to launch only python tests (pytest) when I push my changes, and not all the hooks (flake8, black, etc).

Here my pre-commit config :

default_stages: [commit, push]
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml
    -   id: check-added-large-files
        args: [ "--maxkb=120000" ]
    -   id: check-json
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
    - id: flake8
-   repo: https://github.com/psf/black
    rev: 22.3.0
    hooks:
    -   id: black
        language_version: python3.9
-   repo: https://github.com/pre-commit/mirrors-jshint
    rev: v2.9.7
    hooks:
    -   id: jshint
-   repo: https://github.com/pre-commit/mirrors-scss-lint
    rev: v0.57.1-1
    hooks:
    -   id: scss-lint
-   repo: https://github.com/asottile/reorder_python_imports
    rev: v1.7.0
    hooks:
    -   id: reorder-python-imports
-   repo: local
    hooks:
    -   id: pytest-check
        stages: [push]
        types: [python]
        name: pytest-check
        entry: python -m pytest -v tests/
        language: system
        pass_filenames: false
        always_run: true

How can I do that please ?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
fabrice
  • 1,399
  • 1
  • 15
  • 27

1 Answers1

3

you've found the right option -- you've just misconfigured it !

-default_stages: [commit, push]
+default_stages: [commit]

disclaimer: I created pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • Hi, Thanks, but it's not working. When I commit, the pre-commit run normally. And, when I push, I've 3 actions : "Trim Trailing Whitespace", "Fix End of Files" and "Pytest tests". Not only pytest. – fabrice Sep 09 '22 at 13:56
  • 1
    oh, well I assumed you already knew how to set `stages` since you're already doing that ? – anthony sottile Sep 09 '22 at 23:11
  • Yes, i've add all the `stages` in my `id`. It's working :). Thanks – fabrice Sep 19 '22 at 08:57