-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False Positive W0621: Redefining name %r from outer scope when using pytest fixtures #6531
Comments
Well, apparently this code crash on 2.14.0-dev0 and 2.13.8. Exception on node <Decorators l.2 at 0x7f1be24aaa00> in file '/home/pierre/pylint/b.py'
Traceback (most recent call last):
File "/home/pierre/pylint/pylint/utils/ast_walker.py", line 73, in walk
callback(astroid)
File "/home/pierre/pylint/pylint/checkers/unsupported_version.py", line 64, in visit_decorators
self._check_typing_final(node)
File "/home/pierre/pylint/pylint/checkers/unsupported_version.py", line 79, in _check_typing_final
for decorator in decorators or uninferable_final_decorators(node):
File "/home/pierre/pylint/pylint/checkers/utils.py", line 825, in uninferable_final_decorators
import_node = decorator.expr.lookup(decorator.expr.name)[1][0]
IndexError: tuple index out of range |
We should probably fix the crash, but the issue of handling |
I can take a look. |
I could be wrong but regarding the "Refined name from outer scope" message. Isn't this correct of Pylint in highlighting what is also mentioned in the SO (pytest docs)? If a fixture is used in the same module in which it is defined, the function name of the fixture will be shadowed by the function arg that requests the fixture; one way to resolve this is to name the decorated function fixture and then use @pytest.fixture(name=''). |
Related : #1535 |
How about my comment here: |
These issues are probably best reported to https://github.com/reverbc/pylint-pytest/. Due to the way |
Not sure if there's a specific solution in mind for this, but if the OPs original code
was to emit no errors, I've also had issues where I'll accidentally forget to use the fixture (as an argument), or the correct name, and then I get really confused because the code technically still runs, there's no name redefinition, you just get something strange like an
A 'fix' is to do something like
but it can get a little tedious. My dumb wish is that there was just a prefix you could slap on to functions (e.g.
But that's all in the PyTest camp... |
@mbyrnepr2 - Hey mate should I make you an assignee for fixing the crash? |
Hey @orSolocate that's OK with me. My understanding is that for this issue the solution is to use pylint-pytest; although the status of that project is unclear. |
I agree @mbyrnepr2 (with my own earlier statements 😬). I have started working on my own pytest plugin and this will probably be fixed by it. I'm waiting on confirmation that the current pytest plug-in is unmaintained to start working on it again. I'll come back to this issue when there is any development. For now I think this can stay open as it helps direct users with pytest related issues. |
Since the last status on this issue, https://github.com/reverbc/pylint-pytest has been archived, and would probably require a new maintainer for that to be the solution. However, I do see the very valid point that pytest simply isn't done in a pythonic way and a plugin has to fix the issue. I'm hoping someone will pick up the torch, as I'd love to both use pytest as well as pylint. |
Relevant discussion here: PyCQA/meta#56 |
Bug description
Bug opened from SO issue
Testcase:
They discuss a workaround to avoid the error and also a method of disabling the checker but this bug issue is about actually fixing it in Pylint, or at least discussing it.
Configuration
No response
Pylint output
`W0621: Redefining name %r from outer scope (line %s)'`
Expected behavior
The Pylint message should recognize this situation of pytest fixture decorator and don't raise a message.
Pylint version
OS / Environment
Windows
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: