9

I have my unit tests living alongside my source code. i.e.

├── __init__.py
├── formatter.py
└── test_formatter.py

Is there a way to get Pylint to exclude all files prefixed with test_ from its analysis? The ignore configuration option doesn't seem to like wildcards.

Mr. S
  • 1,469
  • 2
  • 15
  • 27

3 Answers3

14

This was introduced as a feature in Pylint 1.6 via the --ignore-patterns option.

So, to ignore the files above:

pylint myproject --ignore-patterns=test_.*?py
Mr. S
  • 1,469
  • 2
  • 15
  • 27
  • 7
    When I add `ignore-patterns=test_.*?py` to the `[MASTER]` section of my `~/.pylintrc` file, no linting happens anymore. – Martin Thoma May 24 '19 at 07:22
3

Adding the below to [master] section in pylintrc works for me. It will ignore both foo_test.py and test_far.py.

ignore-patterns=(.)*_test\.py,test_(.)*\.py
Adrian W
  • 4,563
  • 11
  • 38
  • 52
RyoJerryYu
  • 31
  • 1
  • You don't need the capturing group, `'.*_test\.py, test_.*\.py'` is fine. Also it's safer to match complete filenames, so, `'^.*_test\.py$, ^test_.*\.py$'`. – Abhijit Sarkar Jun 22 '23 at 19:46
1

there is indeed no wildcard support. You may submit a feature request or even better a pull-request on https://github.com/PyCQA/pylint

Mr. S
  • 1,469
  • 2
  • 15
  • 27
sthenault
  • 14,397
  • 5
  • 38
  • 32