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.

3 Answers 3

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
1
  • 7
    When I add ignore-patterns=test_.*?py to the [MASTER] section of my ~/.pylintrc file, no linting happens anymore. May 24, 2019 at 7: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
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$'. Jun 22 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

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.