I had looked at the pylint source code, and did some python troubleshooting, I discovered the matching was only checking against the beginning of the line.  Someone in the community also offered the same suggestion (which prompted me to reply to my own post in hopes this may help someone else).   In the end, I used the following: 

(?i)(?P<start>^(tests?)?_)|(?P<end>.*tests$)


I know (?P<text>) is not needed as it can't be used, but I find it useful for reading the regular expression and helping determine what a group is expected to match.

Bassam

On Wed, May 29, 2019 at 11:22 AM Bassam Khouri <bassam.khouri@gmail.com> wrote:
Hi,

I'm trying to configure the
no-docstring-rgx option to ignore function and class names that:
- Starts with
_
- Starts with test_
- Ends with tests
- Ends with Tests

I came up with the following regular expression:
(^(test)?_)|((T|t)ests$)

When I test the regular expression on https://regex101.com/r/3BXmsa/6, it matches the text I expect it to match.

However, when I run pylint against my code, it still reports a docstring is missing for a class name that ends with Tests

For example, if I have the following python 3 code.

import unittest


class _Utils(unittest.TestCase):
    pass


class Test_Foo(unittest.TestCase):
    pass


class test_Foo(unittest.TestCase):
    pass


class UtilsTests(unittest.TestCase):

    def test_function_name(self):
        pass

    def _foo(self):
        pass

    def my_tests(self):
        pass


if __name__ == "__main__":
    unittest.main()

Running pylint --disable=all --enable=missing-docstring --no-docstring-rgx='(^(test)?_)|((T|t)ests$)' ./test.py yields

$ pylint --disable=all --enable=missing-docstring --no-docstring-rgx='(^(test)?_)|((T|t)ests$)' ./test.py 

************* Module test

test.py:1:0: C0111: Missing module docstring (missing-docstring)

test.py:8:0: C0111: Missing class docstring (missing-docstring)

test.py:16:0: C0111: Missing class docstring (missing-docstring)

test.py:24:4: C0111: Missing method docstring (missing-docstring)


------------------------------------------------------------------

Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00)


I was only expecting to see the Missing module docstring violation, and the missing class docstring on line 8.

Here is my environment:

$ pylint --version

pylint 2.3.1

astroid 2.2.5

Python 3.7.3 (default, Mar 27 2019, 09:23:15) 

[Clang 10.0.1 (clang-1001.0.46.3)]


Any ideas what is going on and how to fix it?

Cheers,

Bassam
---
"What we can or cannot do, what we consider possible or impossible, is rarely a function of our true capability. It is more likely a function of our beliefs about who we are." - Tony Robbins