'Method name doesn't conform to snake_case naming style

I’m creating a simple project with my pylintrc file and get this error for the test method:

method name - test_calculator_add_method_returns_correct_result -  doesn't conform to snake_case naming style
class TddInPythonExample(unittest.TestCase):
    """ This is a basic test class"""

    def test_calculator_add_method_returns_correct_result(self):
        """ This test the calculator add method """
        calc = Calculator()
        result = calc.add(2,2)
        self.assertEqual(4, result)


Solution 1:[1]

Why is the method name rejected

It appears according to this: http://pylint-messages.wikidot.com/messages:c0103 that the length of the name is capped at 30 characters, where your method name is 49 characters long

The fix

You can shorten the method name, or change your config to allow longer methods

Solution 2:[2]

If you are a Visual Studio Code user who wants to ignore this, you can add python.linting.pylintArgs to .vscode/settings.json:

{
    ...
    "python.linting.pylintArgs": [
        "--disable=C0103"
    ]
    ...
}

Solution 3:[3]

Very well pointed by @jrtapsell

To Add further information:

There is a regular expression defined for each type when it comes to naming convention.

You may note the length of a name can vary from 2 to 30 characters along with its regex.

    +-------------------+---------------+-------------------------------------------+
    |       Type        |    Option     |        Default regular expression         |
    +-------------------+---------------+-------------------------------------------+
    | Argument          | argument-rgx  | [a-z_][a-z0-9_]{2,30}$                    |
    | Attribute         | attr-rgx      | [a-z_][a-z0-9_]{2,30}$                    |
    | Class             | class-rgx     | [A-Z_][a-zA-Z0-9]+$                       |
    | Constant          | const-rgx     | (([A-Z_][A-Z0-9_]*)|(__.*__))$            |
    | Function          | function-rgx  | [a-z_][a-z0-9_]{2,30}$                    |
    | Method            | method-rgx    | [a-z_][a-z0-9_]{2,30}$                    |
    | Module            | module-rgx    | (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ |
    | Variable          | variable-rgx  | [a-z_][a-z0-9_]{2,30}$                    |
    | Variable, inline1 | inlinevar-rgx | [A-Za-z_][A-Za-z0-9_]*$                   |
    +-------------------+---------------+-------------------------------------------+

Source: http://pylint-messages.wikidot.com/messages:c0103

Solution 4:[4]

Also, if you have not generated the .pylinrc file, you can do so using the following command.

pylint --generate-rcfile | out-file -encoding utf8 .pylintrc

then you can change the type of naming case in .pylinrc file, here are some popular cases and sample use case.

PascalCase: NewObject camelCase: newObject PascalCase: LongFunctionName() camelCase: longFunctionName()

Solution 5:[5]

Note that line whenever you get this kind of error. you need to mention your function name in snake_case style. That means

"def TddInPythonExample():": ->  def dd_in_python_example():

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jrtapsell
Solution 2 Bartleby
Solution 3 Akarsh Jain
Solution 4 Wester king
Solution 5 Sindhukumari P