3
3
import logging
4
4
5
5
6
+ # each tuple contains (flag, mark, reason) where:
7
+ # - flag: the cli flag used to enable the tests with that mark
8
+ # - mark: the pytest mark to label a test with to enable skipping
9
+ # - reason: the description of why that mark exists
10
+ test_skip_marks = [
11
+ ("--runslow" , "slow" , "are long running" ),
12
+ ("--runrobot" , "robot_required" , "require a connected Eva" ),
13
+ ("--io_loopback" , "io_loopback_required" , "require head and base IO loopback cables connected to Eva" ),
14
+ ]
15
+
16
+
6
17
def pytest_addoption (parser ):
7
18
parser .addoption ("--ip" , default = '172.16.16.2' , help = "IP of the test robot, defaults to 172.16.16.2" )
8
19
parser .addoption ("--token" , default = '' , help = "API token of the test robot" )
9
- parser .addoption ("--runslow" , action = "store_true" , default = False , help = "run slow tests" )
10
- parser .addoption ("--runrobot" , action = "store_true" , default = False , help = "run tests that require a connected Eva" )
11
- parser .addoption (
12
- "--io_loopback" ,
13
- action = "store_true" ,
14
- default = False ,
15
- help = "run tests that require head and base IO loopback cables connected to Eva" ,
16
- )
20
+ for (flag , _ , reason ) in test_skip_marks :
21
+ parser .addoption (
22
+ flag ,
23
+ action = "store_true" ,
24
+ default = False ,
25
+ help = f'run tests that { reason } ' ,
26
+ )
27
+
28
+
29
+ def pytest_configure (config ):
30
+ for (_ , mark , reason ) in test_skip_marks :
31
+ config .addinivalue_line ("markers" , f'{ mark } : marked tests { reason } ' )
32
+
33
+
34
+ def pytest_collection_modifyitems (config , items ):
35
+ for (flag , mark , _ ) in test_skip_marks :
36
+ if not config .getoption (flag ):
37
+ skip_mark = pytest .mark .skip (reason = f'needs { flag } option to run' )
38
+ for item in items :
39
+ if mark in item .keywords :
40
+ item .add_marker (skip_mark )
17
41
18
42
19
43
@pytest .fixture (scope = "session" )
@@ -26,39 +50,6 @@ def token(request):
26
50
return request .config .getoption ("--token" )
27
51
28
52
29
- def pytest_configure (config ):
30
- config .addinivalue_line ("markers" , "slow: mark test as slow to run" )
31
- config .addinivalue_line ("markers" , "robot_required: no mocks, needs a connected Eva to run" )
32
- config .addinivalue_line (
33
- "markers" ,
34
- "io_loopback_required: require head and base IO loopback cables connected to Eva" ,
35
- )
36
-
37
-
38
- def pytest_collection_modifyitems (config , items ):
39
- # --runslow given in cli: do not skip slow tests
40
- if not config .getoption ("--runslow" ):
41
- skip_slow = pytest .mark .skip (reason = "need --runslow option to run" )
42
- for item in items :
43
- if "slow" in item .keywords :
44
- item .add_marker (skip_slow )
45
-
46
- # --runrobot given in cli: do not skip tests where a connected Eva is required
47
- if not config .getoption ("--runrobot" ):
48
- skip_robot_required = pytest .mark .skip (reason = "need --runrobot option to run" )
49
- for item in items :
50
- if "robot_required" in item .keywords :
51
- item .add_marker (skip_robot_required )
52
-
53
- # --io_loopback given in cli: do not skip tests requiring
54
- # attached base and ee IO loopback cables
55
- if not config .getoption ("--io_loopback" ):
56
- skip_io_loopback_required = pytest .mark .skip (reason = "need --io_loopback option to run" )
57
- for item in items :
58
- if "io_loopback_required" in item .keywords :
59
- item .add_marker (skip_io_loopback_required )
60
-
61
-
62
53
@pytest .fixture (scope = "module" )
63
54
def eva (ip , token ):
64
55
e = Eva (ip , token , request_timeout = 10 , renew_period = 2 * 60 )
0 commit comments