|
7 | 7 |
|
8 | 8 | import astroid
|
9 | 9 | import pytest
|
10 |
| -from pylint.checkers.variables import VariablesChecker |
11 | 10 |
|
12 | 11 | from ..utils import (
|
13 | 12 | _can_use_fixture,
|
14 | 13 | _is_pytest_fixture,
|
15 | 14 | _is_pytest_mark,
|
16 | 15 | _is_pytest_mark_usefixtures,
|
17 |
| - _is_same_module, |
18 | 16 | )
|
19 | 17 | from . import BasePytestChecker
|
20 |
| -from .types import FixtureDict, replacement_add_message |
| 18 | +from .types import FixtureDict |
21 | 19 |
|
22 | 20 | # TODO: support pytest python_files configuration
|
23 | 21 | FILE_NAME_PATTERNS: tuple[str, ...] = ("test_*.py", "*_test.py")
|
@@ -80,19 +78,9 @@ class FixtureChecker(BasePytestChecker):
|
80 | 78 | _invoked_with_func_args: set[str] = set()
|
81 | 79 | # Stores all invoked fixtures through @pytest.mark.usefixture(...)
|
82 | 80 | _invoked_with_usefixtures: set[str] = set()
|
83 |
| - _original_add_message = replacement_add_message |
84 |
| - |
85 |
| - def open(self): |
86 |
| - # patch VariablesChecker.add_message |
87 |
| - FixtureChecker._original_add_message = VariablesChecker.add_message |
88 |
| - VariablesChecker.add_message = FixtureChecker.patch_add_message |
89 | 81 |
|
90 | 82 | def close(self):
|
91 | 83 | """restore & reset class attr for testing"""
|
92 |
| - # restore add_message |
93 |
| - VariablesChecker.add_message = FixtureChecker._original_add_message |
94 |
| - FixtureChecker._original_add_message = replacement_add_message |
95 |
| - |
96 | 84 | # reset fixture info storage
|
97 | 85 | FixtureChecker._pytest_fixtures = {}
|
98 | 86 | FixtureChecker._invoked_with_func_args = set()
|
@@ -232,84 +220,3 @@ def visit_functiondef(self, node):
|
232 | 220 | self.add_message("deprecated-pytest-yield-fixture", node=node)
|
233 | 221 | for arg in node.args.args:
|
234 | 222 | self._invoked_with_func_args.add(arg.name)
|
235 |
| - |
236 |
| - # pylint: disable=bad-staticmethod-argument # The function itself is an if-return logic. |
237 |
| - @staticmethod |
238 |
| - def patch_add_message( |
239 |
| - self, msgid, line=None, node=None, args=None, confidence=None, col_offset=None |
240 |
| - ): |
241 |
| - """ |
242 |
| - - intercept and discard unwanted warning messages |
243 |
| - """ |
244 |
| - # check W0611 unused-import |
245 |
| - if msgid == "unused-import": |
246 |
| - # actual attribute name is not passed as arg so...dirty hack |
247 |
| - # message is usually in the form of '%s imported from %s (as %)' |
248 |
| - message_tokens = args.split() |
249 |
| - fixture_name = message_tokens[0] |
250 |
| - |
251 |
| - # ignoring 'import %s' message |
252 |
| - if message_tokens[0] == "import" and len(message_tokens) == 2: |
253 |
| - pass |
254 |
| - |
255 |
| - # fixture is defined in other modules and being imported to |
256 |
| - # conftest for pytest magic |
257 |
| - elif ( |
258 |
| - isinstance(node.parent, astroid.Module) |
259 |
| - and node.parent.name.split(".")[-1] == "conftest" |
260 |
| - and fixture_name in FixtureChecker._pytest_fixtures |
261 |
| - ): |
262 |
| - return |
263 |
| - |
264 |
| - # imported fixture is referenced in test/fixture func |
265 |
| - elif ( |
266 |
| - fixture_name in FixtureChecker._invoked_with_func_args |
267 |
| - and fixture_name in FixtureChecker._pytest_fixtures |
268 |
| - ): |
269 |
| - if _is_same_module( |
270 |
| - fixtures=FixtureChecker._pytest_fixtures, |
271 |
| - import_node=node, |
272 |
| - fixture_name=fixture_name, |
273 |
| - ): |
274 |
| - return |
275 |
| - |
276 |
| - # fixture is referenced in @pytest.mark.usefixtures |
277 |
| - elif ( |
278 |
| - fixture_name in FixtureChecker._invoked_with_usefixtures |
279 |
| - and fixture_name in FixtureChecker._pytest_fixtures |
280 |
| - ): |
281 |
| - if _is_same_module( |
282 |
| - fixtures=FixtureChecker._pytest_fixtures, |
283 |
| - import_node=node, |
284 |
| - fixture_name=fixture_name, |
285 |
| - ): |
286 |
| - return |
287 |
| - |
288 |
| - # check W0613 unused-argument |
289 |
| - if ( |
290 |
| - msgid == "unused-argument" |
291 |
| - and _can_use_fixture(node.parent.parent) |
292 |
| - and isinstance(node.parent, astroid.Arguments) |
293 |
| - ): |
294 |
| - if node.name in FixtureChecker._pytest_fixtures: |
295 |
| - # argument is used as a fixture |
296 |
| - return |
297 |
| - |
298 |
| - fixnames = ( |
299 |
| - arg.name for arg in node.parent.args if arg.name in FixtureChecker._pytest_fixtures |
300 |
| - ) |
301 |
| - for fixname in fixnames: |
302 |
| - if node.name in FixtureChecker._pytest_fixtures[fixname][0].argnames: |
303 |
| - # argument is used by a fixture |
304 |
| - return |
305 |
| - |
306 |
| - # check W0621 redefined-outer-name |
307 |
| - if ( |
308 |
| - msgid == "redefined-outer-name" |
309 |
| - and _can_use_fixture(node.parent.parent) |
310 |
| - and isinstance(node.parent, astroid.Arguments) |
311 |
| - and node.name in FixtureChecker._pytest_fixtures |
312 |
| - ): |
313 |
| - return |
314 |
| - |
315 |
| - FixtureChecker._original_add_message(self, msgid, line, node, args, confidence, col_offset) |
0 commit comments