mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[python] PY-63483, PY-83912, PY-70815 False positive warning Fixture '...' is not requested by test functions for attributes
Merge-request: IJ-MR-181099 Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com> (cherry picked from commit 7299d76d38ae5a823a3b0cae7ba5e2a0cc693d13) IJ-MR-181099 GitOrigin-RevId: 82be14096cccf01de85fcf7f7abb4af2fd838193
This commit is contained in:
committed by
intellij-monorepo-bot
parent
798bbf238c
commit
50fa4b90d2
+14
@@ -63,6 +63,20 @@ class PyTestUnpassedFixtureInspection : PyInspection() {
|
||||
// no warning if a fixture is in '@pytest.mark.usefixtures' arguments
|
||||
if (isParameterInDecorator(element, testFunction)) return
|
||||
|
||||
// if a reference resolves to a local binding target (assignment/with/for/walrus),
|
||||
// then it's not a fixture usage and should be ignored.
|
||||
element.reference.resolve()?.let { resolved ->
|
||||
when (resolved) {
|
||||
is PyTargetExpression -> return
|
||||
is PyNamedParameter -> Unit // parameters are handled above
|
||||
else -> Unit // do not early-return for functions/imports/etc.
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore all qualified attribute references (e.g., self.fixture, module.fixture)
|
||||
// PyTest fixtures are not requested via qualified names, so treat them as non-fixture usages.
|
||||
if (element.qualifier != null) return
|
||||
|
||||
// no warning if an element has type OTHER
|
||||
if (getType(element) == ResolveType.OTHER) return
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
|
||||
class C:
|
||||
async def bla(self):
|
||||
...
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def create():
|
||||
yield C()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
async def test_():
|
||||
async with create() as client:
|
||||
assert await client.bla() == 1 # no inspection warning expected
|
||||
@@ -0,0 +1,14 @@
|
||||
import pytest
|
||||
|
||||
|
||||
class Unrelated:
|
||||
...
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fixture():
|
||||
return True
|
||||
|
||||
|
||||
def test_():
|
||||
assert Unrelated().fixture # no inspection warning expected
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import pytest
|
||||
|
||||
|
||||
class TestBla:
|
||||
@pytest.fixture
|
||||
def my_f(self):
|
||||
...
|
||||
|
||||
def test_(self):
|
||||
self.my_f() # no inspection warning expected
|
||||
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
||||
class C:
|
||||
def bla(self):
|
||||
...
|
||||
|
||||
|
||||
@contextmanager
|
||||
def create():
|
||||
yield C()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
def test_():
|
||||
with create() as client:
|
||||
assert client.bla() == 1 # no inspection warning expected
|
||||
@@ -55,4 +55,20 @@ class PyTestUnpassedFixtureInspectionTest : PyInspectionTestCase() {
|
||||
fun testNoInspectCorrectCode() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testWithShadowing() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testAsyncWithShadowing() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testAttributeShadowing() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testQualifiedClassFixtureCall() {
|
||||
doTest()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user