Skip to content

Commit c75e66c

Browse files
authored
Merge pull request github#16762 from github/redsun82/python-disregard-unused-imports-in-pytest-tests
Python: failing unused import test case
2 parents 2f00a0d + 1046d03 commit c75e66c

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

python/ql/test/query-tests/Imports/unused/UnusedImport.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
| imports_test.py:10:1:10:22 | Import | Import of 'top_level_cycle' is not used. |
66
| imports_test.py:27:1:27:25 | Import | Import of 'func2' is not used. |
77
| imports_test.py:34:1:34:14 | Import | Import of 'module2' is not used. |
8-
| imports_test.py:116:1:116:85 | Import | Import of 'fixture_instance' is not used. |
9-
| imports_test.py:116:1:116:85 | Import | Import of 'not_a_fixture' is not used. |
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. |

python/ql/test/query-tests/Imports/unused/imports_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ def baz() -> Optional['subexpression_return_type']:
113113
pass
114114

115115

116-
from pytest_fixtures import fixture, wrapped_fixture, fixture_instance, not_a_fixture
116+
from pytest_fixtures import not_a_fixture # BAD
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]

python/ql/test/query-tests/Imports/unused/pytest_fixtures.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ def delegate():
1515
def wrapped_fixture():
1616
pass
1717

18-
@pytest.fixture(scope='session', autorun=True)
19-
def factory_fixture():
20-
pass
2118

22-
fixture_instance = factory_fixture()
19+
@pytest.fixture(scope='session')
20+
def session_fixture():
21+
pass
2322

2423
def not_a_fixture():
2524
pass
25+
26+
def another_fixture_wrapper():
27+
@pytest.fixture(autouse=True)
28+
def delegate():
29+
pass
30+
return delegate
31+
32+
@another_fixture_wrapper
33+
def wrapped_autouse_fixture():
34+
pass

0 commit comments

Comments
 (0)