1
1
import astroid
2
2
from pylint .interfaces import IAstroidChecker
3
+
3
4
from ..utils import _can_use_fixture , _is_class_autouse_fixture
4
5
from . import BasePytestChecker
5
6
6
7
7
8
class ClassAttrLoader (BasePytestChecker ):
8
9
__implements__ = IAstroidChecker
9
- msgs = {' E6400' : ('' , ' pytest-class-attr-loader' , '' )}
10
+ msgs = {" E6400" : ("" , " pytest-class-attr-loader" , "" )}
10
11
11
12
in_setup = False
12
13
request_cls = set ()
13
14
class_node = None
14
15
15
16
def visit_functiondef (self , node ):
16
- ''' determine if a method is a class setup method'''
17
+ """ determine if a method is a class setup method"""
17
18
self .in_setup = False
18
19
self .request_cls = set ()
19
20
self .class_node = None
@@ -23,17 +24,23 @@ def visit_functiondef(self, node):
23
24
self .class_node = node .parent
24
25
25
26
def visit_assign (self , node ):
26
- '''store the aliases for `cls`'''
27
- if self .in_setup and isinstance (node .value , astroid .Attribute ) and \
28
- node .value .attrname == 'cls' and \
29
- node .value .expr .name == 'request' :
27
+ """store the aliases for `cls`"""
28
+ if (
29
+ self .in_setup
30
+ and isinstance (node .value , astroid .Attribute )
31
+ and node .value .attrname == "cls"
32
+ and node .value .expr .name == "request"
33
+ ):
30
34
# storing the aliases for cls from request.cls
31
35
self .request_cls = set (map (lambda t : t .name , node .targets ))
32
36
33
37
def visit_assignattr (self , node ):
34
- if self .in_setup and isinstance (node .expr , astroid .Name ) and \
35
- node .expr .name in self .request_cls and \
36
- node .attrname not in self .class_node .locals :
38
+ if (
39
+ self .in_setup
40
+ and isinstance (node .expr , astroid .Name )
41
+ and node .expr .name in self .request_cls
42
+ and node .attrname not in self .class_node .locals
43
+ ):
37
44
try :
38
45
# find Assign node which contains the source "value"
39
46
assign_node = node
0 commit comments