Description
Describe the bug
POC: https://github.com/flamusdiu/pytest-poc-bug
If you create a test file as:
def t(a):
pass
Why you might do this? Maybe there is some dynamic testing or something where you want to change the function. However this causes an exception: https://github.com/flamusdiu/pytest-poc-bug/blob/main/error.txt
To Reproduce
Test Requirements
astroid==3.3.9; python_version >= '3.12'
pylint==3.3.7; python_version >= '3.12'
pylint-pytest==1.1.8 # suppresses false positives from pytest
pytest==8.2.0; python_version >= '3.12'
Folder structure
See https://github.com/flamusdiu/pytest-poc-bug
File content
pylint output with the plugin
Exception on node <FunctionDef.t l.2 at 0xffff9d100c50> in file '/workspaces/test_pytest/tests/test_example.py'
Traceback (most recent call last):
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 92, in walk
callback(astroid)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/checkers/variables.py", line 1581, in leave_functiondef
self._check_is_unused(
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/checkers/variables.py", line 2779, in _check_is_unused
self._check_unused_arguments(name, node, stmt, argnames, nonlocal_names)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/checkers/variables.py", line 2902, in _check_unused_arguments
self.add_message("unused-argument", args=name, node=stmt, confidence=confidence)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 314, in patch_add_message
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 314, in patch_add_message
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 314, in patch_add_message
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
[Previous line repeated 967 more times]
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 290, in patch_add_message
and _can_use_fixture(node.parent.parent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 831, in _check_file
check_astroid_module(ast_node)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1020, in check_astroid_module
retval = self._check_astroid_module(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1072, in _check_astroid_module
walker.walk(node)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 90, in walk
self.walk(child)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 92, in walk
callback(astroid)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/checkers/variables.py", line 1581, in leave_functiondef
self._check_is_unused(
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/checkers/variables.py", line 2779, in _check_is_unused
self._check_unused_arguments(name, node, stmt, argnames, nonlocal_names)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/checkers/variables.py", line 2902, in _check_unused_arguments
self.add_message("unused-argument", args=name, node=stmt, confidence=confidence)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 314, in patch_add_message
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 314, in patch_add_message
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 314, in patch_add_message
FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset)
[Previous line repeated 967 more times]
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint_pytest/checkers/fixture.py", line 290, in patch_add_message
and _can_use_fixture(node.parent.parent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.12/concurrent/futures/process.py", line 264, in _process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/process.py", line 213, in _process_chunk
return [fn(*args) for args in chunk]
^^^^^^^^^
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/parallel.py", line 79, in _worker_check_single_file
_worker_linter.check_single_file_item(file_item)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 740, in check_single_file_item
self._check_file(self.get_ast, check_astroid_module, file)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 833, in _check_file
raise astroid.AstroidError from e
astroid.exceptions.AstroidError
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/workspaces/test_pytest/.venv/bin/pylint", line 8, in <module>
sys.exit(run_pylint())
^^^^^^^^^^^^
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/__init__.py", line 34, in run_pylint
PylintRun(argv or sys.argv[1:])
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/run.py", line 240, in __init__
linter.check(args)
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 679, in check
check_parallel(
File "/workspaces/test_pytest/.venv/lib/python3.12/site-packages/pylint/lint/parallel.py", line 162, in check_parallel
) in executor.map(_worker_check_single_file, files):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/process.py", line 636, in _chain_from_iterable_of_lists
for element in iterable:
^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/_base.py", line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/_base.py", line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
astroid.exceptions.AstroidError
(Optional) pytest output from fixture collection
$ pytest --fixtures --collect-only <path/to/test/module.py>
<paste output here, can omit the built-ins>
Expected behavior
This probably shouldn't error out due to this kind of function
Additional context
Looks like the file
Contains where the check happens.