Skip to content

Commit e31eb37

Browse files
charlesworthCharlesworth
charlesworth
authored andcommitted
added tuples for adding new test flags
1 parent 5c6026e commit e31eb37

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

tests/conftest.py

+32-41
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,41 @@
33
import logging
44

55

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+
617
def pytest_addoption(parser):
718
parser.addoption("--ip", default='172.16.16.2', help="IP of the test robot, defaults to 172.16.16.2")
819
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)
1741

1842

1943
@pytest.fixture(scope="session")
@@ -26,39 +50,6 @@ def token(request):
2650
return request.config.getoption("--token")
2751

2852

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-
6253
@pytest.fixture(scope="module")
6354
def eva(ip, token):
6455
e = Eva(ip, token, request_timeout=10, renew_period=2 * 60)

0 commit comments

Comments
 (0)