Skip to content

Commit 360461c

Browse files
committed
Make nsp/nate/better-unused-argument merge-able with origin/master
Signed-off-by: Stavros Ntentos <[email protected]>
1 parent bb0b523 commit 360461c

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

pylint_pytest/checkers/fixture.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def visit_functiondef(self, node):
196196
for arg in node.args.args:
197197
self._invoked_with_func_args.add(arg.name)
198198

199-
# pylint: disable=protected-access,bad-staticmethod-argument
199+
# pylint: disable=bad-staticmethod-argument,too-many-branches # The function itself is an if-return logic.
200200
@staticmethod
201201
def patch_add_message(self, msgid, line=None, node=None, args=None,
202202
confidence=None, col_offset=None):
@@ -238,16 +238,22 @@ def patch_add_message(self, msgid, line=None, node=None, args=None,
238238
return
239239

240240
# check W0613 unused-argument
241-
if msgid == 'unused-argument':
242-
if _can_use_fixture(node.parent.parent):
243-
if isinstance(node.parent, astroid.Arguments):
244-
if node.name in FixtureChecker._pytest_fixtures:
245-
return # argument is used as a fixture
246-
else:
247-
fixnames = (arg.name for arg in node.parent.args if arg.name in FixtureChecker._pytest_fixtures)
248-
for fixname in fixnames:
249-
if node.name in FixtureChecker._pytest_fixtures[fixname][0].argnames:
250-
return # argument is used by a fixture
241+
if (
242+
msgid == "unused-argument"
243+
and _can_use_fixture(node.parent.parent)
244+
and isinstance(node.parent, astroid.Arguments)
245+
):
246+
if node.name in FixtureChecker._pytest_fixtures:
247+
# argument is used as a fixture
248+
return
249+
250+
fixnames = (
251+
arg.name for arg in node.parent.args if arg.name in FixtureChecker._pytest_fixtures
252+
)
253+
for fixname in fixnames:
254+
if node.name in FixtureChecker._pytest_fixtures[fixname][0].argnames:
255+
# argument is used by a fixture
256+
return
251257

252258
# check W0621 redefined-outer-name
253259
if msgid == 'redefined-outer-name' and \

tests/input/unused-argument/func_param_as_fixture_arg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_myfix(myfix, arg):
1818
"""A test function that uses the param through a fixture"""
1919
assert myfix
2020

21+
2122
@pytest.mark.parametrize("narg", [4, 5, 6])
2223
def test_nyfix(narg): # unused-argument
2324
"""A test function that does not use its param"""

tests/test_unused_argument.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77
class TestUnusedArgument(BasePytestTester):
88
CHECKER_CLASS = FixtureChecker
99
IMPACTED_CHECKER_CLASSES = [VariablesChecker]
10-
MSG_ID = 'unused-argument'
10+
MSG_ID = "unused-argument"
1111

12-
@pytest.mark.parametrize('enable_plugin', [True, False])
12+
@pytest.mark.parametrize("enable_plugin", [True, False])
1313
def test_smoke(self, enable_plugin):
1414
self.run_linter(enable_plugin)
1515
self.verify_messages(0 if enable_plugin else 2)
1616

17-
@pytest.mark.parametrize('enable_plugin', [True, False])
17+
@pytest.mark.parametrize("enable_plugin", [True, False])
1818
def test_caller_yield_fixture(self, enable_plugin):
1919
self.run_linter(enable_plugin)
2020
self.verify_messages(0 if enable_plugin else 1)
2121

22-
@pytest.mark.parametrize('enable_plugin', [True, False])
22+
@pytest.mark.parametrize("enable_plugin", [True, False])
2323
def test_caller_not_a_test_func(self, enable_plugin):
2424
self.run_linter(enable_plugin)
2525
self.verify_messages(1)
2626

27-
@pytest.mark.parametrize('enable_plugin', [True, False])
27+
@pytest.mark.parametrize("enable_plugin", [True, False])
2828
def test_args_and_kwargs(self, enable_plugin):
2929
self.run_linter(enable_plugin)
3030
self.verify_messages(2)
3131

32-
@pytest.mark.parametrize('enable_plugin', [True, False])
32+
@pytest.mark.parametrize("enable_plugin", [True, False])
3333
def test_func_param_as_fixture_arg(self, enable_plugin):
3434
self.run_linter(enable_plugin)
3535
self.verify_messages(1 if enable_plugin else 2)

0 commit comments

Comments
 (0)