-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
importing pytest fixtures raises F401 #4046
Comments
Thanks for filing. I'll look into this! |
I think this has been discussed before, but I’m on my phone and it may be hard to dig up the relevant issue. |
#3295 pointed me to this. Pytest suggests avoiding importing fixtures in favor of adding them to I'm almost leaning towards fixing the unused import bug, but maybe implementing a separate rule centered on avoiding fixture imports? FWIW, it seems like Pylint has the same issue as the one mentioned here. The suggested solution is to simply rename the fixture file ( |
Yeah, reading through the discussion, I think I agree with the conclusion that was reached in #3295: since Pytest itself recommends against this pattern, I'd rather not special-case in Ruff. (I'm not even sure how we could special-case it without introducing lots of false negatives. Best-case is that we could avoid autofixing these cases but still flag them.) |
I'm going to close, given that conclusion, but always happy to continue the discussion. |
Thank you very much for that! I’m a novice with pytest and this was a case of me using a linter to help me muddle through, and it has 😜 |
Today,
I went with option 3, marking |
Importing fixtures is a pytest antipattern and causes Ruff to flag F811. See astral-sh/ruff#4046. Defining fixtures globally in conftest.py is the idiomatic way to remedy the problem.
Importing fixtures is a pytest antipattern and causes Ruff to flag F811. See astral-sh/ruff#4046. Defining fixtures globally in conftest.py is the idiomatic way to remedy the problem.
Importing fixtures is a pytest antipattern and causes Ruff to flag F811. See astral-sh/ruff#4046. Defining fixtures globally in conftest.py is the idiomatic way to remedy the problem.
It appears that ruff isn't handling pytest fixtures correctly.
Consider the following files (adapted from a pytest example):
fruit.py
and test_fruit.py:
Running
ruff --isolated test_fruit.py
I get:I'm using
ruff 0.0.262
The text was updated successfully, but these errors were encountered: