This is mainly related to Pytests fixtures where fixtures always raise "redefined-outer-name" error.
A setting could be added to ignore some names based on regex.
Some possibilities :
# basic
ignore-redefined-outer-name=fixture_abs,fixtures_foo,fixture_bar
# "start by"
ignore-redefined-outer-name=fixture_
# regex
ignore-redefined-outer-name-rgx=fixture_[a-z]$
Example or problem :
import smtplib
import pytest
@pytest.fixture
def fixture_smtp():
"""Pytest fixture"""
return smtplib.SMTP("smtp.gmail.com")
def test_ehlo(fixture_smtp):
"""Example"""
response, msg = fixture_smtp.ehlo()
assert response == 42
assert msg == 'foo'
Result :
➜ tmp pylint example.py
No config file found, using default configuration
************* Module example
W: 14,14: Redefining name 'fixture_smtp' from outer scope (line 9) (redefined-outer-name)
[...]
Messages
--------
+---------------------+------------+
|message id |occurrences |
+=====================+============+
|redefined-outer-name |1 |
+---------------------+------------+
Global evaluation
-----------------
Your code has been rated at 8.75/10
This sounds good to me. If anyone has time to tackle this and send a PR, that would be definitely appreciated.
I'll send a PR in next days/weeks.
A solution for this is to use the name attr of the fixture decorator:
@pytest.fixture
def fixture_smtp(name="smtp"):
"""Pytest fixture"""
return smtplib.SMTP("smtp.gmail.com")
def test_ehlo(smtp):
"""Example"""
response, msg = smtp.ehlo()
assert response == 42
assert msg == 'foo'
(I personally like to avoid pylint-disables where there is another clean option)
I'm not working anymore on this project so I can't tell you if it's fine but thank you !
I'm not working anymore on this project so I can't tell you if it's fine but thank you !
@gustavi
Correct:
@pytest.fixture(name="smtp")
def fixture_smtp:
"""Pytest fixture"""
return smtplib.SMTP("smtp.gmail.com")
def test_ehlo(smtp):
"""Example"""
response, msg = smtp.ehlo()
assert response == 42
assert msg == 'foo'
Add name parameter for fixture and fixture_ prefix in def.
Most helpful comment
Correct:
Add name parameter for fixture and fixture_ prefix in def.