Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tearDown/setUp considered an invalid name for classes inherited indirectly from TestCase #4060

Closed
socketpair opened this issue Feb 2, 2021 · 11 comments · Fixed by pylint-dev/astroid#1127
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Minor 💅 Polishing pylint is always nice Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)

Comments

@socketpair
Copy link

socketpair commented Feb 2, 2021

C0103: Method name "tearDown" doesn't conform to '^(test_)?[a-z_][a-z0-9_]{2,30}$' pattern ('^(test_)?[a-z_][a-z0-9_]{2,30}$' pattern) (invalid-name)

I have:

method-rgx=^(test_)?[a-z_][a-z0-9_]{2,30}$

Seems because pylint does not recognize IsolatedAsyncioTestCase in same way as TestCase

@socketpair
Copy link
Author

@hippo91

@Pierre-Sassoulas
Copy link
Member

I would advise to modify the regex in the configuration:

[BASIC]

# Regular expression matching correct method names
# Pylint do not complain for setUp and other if it
# detects that we inherit from unittest.TestCase
# But that's not always possible to detect.
method-rgx=[a-z_][a-z0-9_]{2,30}$|setUp(Class)?|tearDown(Class)?

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Minor 💅 Polishing pylint is always nice labels Feb 6, 2021
@hippo91
Copy link
Contributor

hippo91 commented Feb 6, 2021

@Pierre-Sassoulas it makes sense. Thank you. May we close the issue?

@Pierre-Sassoulas
Copy link
Member

This is a real problem in pylint but I don't think it's going to be handled any time soon. If it is, it will probably be in a very generic issue involving astroid guessing the right inherited class (?). I wouldn't mind closing it. Maybe we could fix this by updating the default regex directly inside pylnt ?

@Pierre-Sassoulas Pierre-Sassoulas changed the title pylint considers tearDown as invalid name for test classes inhereited from IsolatedAsyncioTestCase tearDown/setUp considered an invalid name for classes inherited indirectly from TestCase Feb 9, 2021
@hippo91
Copy link
Contributor

hippo91 commented Feb 16, 2021

@socketpair can you give a snippet please?
So that i can evaluate the amount of work to be done to handle this.
Thanks.

@socketpair
Copy link
Author

class BaseTestEtcd(IsolatedAsyncioTestCase):
    @classmethod
    def tearDownClass(cls):
        ...

    def setUp(self):
        ...

@socketpair
Copy link
Author

@hippo91

@hippo91
Copy link
Contributor

hippo91 commented Mar 5, 2021

@socketpair thanks for the snippet. I will work on it ASAP.

@socketpair
Copy link
Author

@hippo91 Do you have any progress on it ?

@hippo91
Copy link
Contributor

hippo91 commented Jun 15, 2021

@socketpair i am sorry i did not have time to work on this.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) label Jun 15, 2021
@hippo91
Copy link
Contributor

hippo91 commented Aug 10, 2021

@socketpair i investigated a bit the problem.
This is due to the way IsolatedAsyncioTestCase is imported through unittest (dynamic lazy import). I will work for a solution ASAP. Meanwhile you can replace from unittest import IsolatedAsyncioTestCase with from unittest.async_case import IsolatedAyncioTestCase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Minor 💅 Polishing pylint is always nice Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants