File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
test/query-tests/Imports/unused Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,24 @@ import Variables.Definition
15
15
import semmle.python.ApiGraphs
16
16
17
17
private predicate is_pytest_fixture ( Import imp , Variable name ) {
18
- exists ( Alias a |
18
+ exists ( Alias a , API:: Node pytest_fixture , API:: Node decorator |
19
+ pytest_fixture = API:: moduleImport ( "pytest" ) .getMember ( "fixture" ) and
20
+ // The additional `.getReturn()` is to account for the difference between
21
+ // ```
22
+ // @pytest.fixture
23
+ // def foo():
24
+ // ...
25
+ // ```
26
+ // and
27
+ // ```
28
+ // @pytest.fixture(some, args, here)
29
+ // def foo():
30
+ // ...
31
+ // ```
32
+ decorator in [ pytest_fixture , pytest_fixture .getReturn ( ) ] and
19
33
a = imp .getAName ( ) and
20
34
a .getAsname ( ) .( Name ) .getVariable ( ) = name and
21
- API:: moduleImport ( "pytest" )
22
- .getMember ( "fixture" )
23
- .getReturn ( )
24
- .getAValueReachableFromSource ( )
25
- .asExpr ( ) = a .getValue ( )
35
+ a .getValue ( ) = decorator .getReturn ( ) .getAValueReachableFromSource ( ) .asExpr ( )
26
36
)
27
37
}
28
38
Original file line number Diff line number Diff line change 6
6
| imports_test.py:27:1:27:25 | Import | Import of 'func2' is not used. |
7
7
| imports_test.py:34:1:34:14 | Import | Import of 'module2' is not used. |
8
8
| imports_test.py:116:1:116:41 | Import | Import of 'not_a_fixture' is not used. |
9
- | imports_test.py:118:1:118:68 | Import | Import of 'session_fixture' is not used. |
10
- | imports_test.py:118:1:118:68 | Import | Import of 'wrapped_autouse_fixture' is not used. |
Original file line number Diff line number Diff line change @@ -115,4 +115,4 @@ def baz() -> Optional['subexpression_return_type']:
115
115
116
116
from pytest_fixtures import not_a_fixture # BAD
117
117
from pytest_fixtures import fixture , wrapped_fixture # GOOD (pytest fixtures are used implicitly by pytest)
118
- from pytest_fixtures import session_fixture , wrapped_autouse_fixture # GOOD [FALSE POSITIVE]
118
+ from pytest_fixtures import session_fixture , wrapped_autouse_fixture # GOOD (pytest fixtures are used implicitly by pytest)
You can’t perform that action at this time.
0 commit comments