Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Test files from precommit hook

Use case- Exclude all test files from flake8. In my project I have test files in different folders.

Current implementation:

  - repo: https://gitlab.com/PyCQA/flake8
    rev: 4.0.1
    hooks:
      - id: flake8
        exclude: ^tests

Current Output:

integration-tests/test_1.py:21:1: F401 'pytest' imported but unused

Expected output: it should pass. It should not check tests.

like image 459
Isha Nema Avatar asked Oct 23 '25 00:10

Isha Nema


1 Answers

you've excluded things which match the pattern ^tests and you have an error in integration-tests

your pattern needs to match those to exclude it properly

for example:

repos:
  - repo: https://gitlab.com/PyCQA/flake8
    rev: 4.0.1
    hooks:
      - id: flake8
        exclude ^integration-tests/

or if you have both test paths, perhaps:

        exclude: ^(tests|integration-tests)/

more on this in the documentation


disclaimer: I created pre-commit

like image 71
Anthony Sottile Avatar answered Oct 24 '25 13:10

Anthony Sottile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!