-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconftest.py
More file actions
73 lines (61 loc) · 2.45 KB
/
conftest.py
File metadata and controls
73 lines (61 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Pytest configuration for the drunc project.
Registers custom command-line options and test markers.
"""
def pytest_addoption(parser):
"""Register custom command-line options for pytest"""
parser.addoption(
"--test-grpc",
action="store_true",
default=False,
help="Run gRPC isolation tests for checking gRPC version and settings compatibility",
)
parser.addoption(
"--test-paramiko",
action="store_true",
default=False,
help="Run tests requiring Paramiko for SSH connections",
)
parser.addoption(
"--test-all",
action="store_true",
default=False,
help="Run all tests, including optional ones",
)
def pytest_collection_modifyitems(config, items):
"""Modify collected test items based on command-line options"""
import pytest
def add_skip_marker(marker_name, reason):
"""Apply skip marker to all tests with the specified marker if option not enabled
Args:
marker_name: The pytest marker to look for (e.g., 'grpc')
reason: The skip reason message shown when tests are skipped
"""
skip_marker = pytest.mark.skip(reason=reason)
for item in items:
if item.get_closest_marker(marker_name):
item.add_marker(skip_marker)
def skip_if_no_option(marker_name, option_name, reason):
"""
Helper function to skip tests with a specific marker if the corresponding command-line option is not enabled.
Args:
marker_name: The pytest marker to look for (e.g., 'grpc')
option_name: The command-line option to check (e.g., '--test-grpc')
reason: The skip reason message shown when tests are skipped
"""
if not config.getoption(option_name):
add_skip_marker(marker_name, reason)
if config.getoption("--test-all"):
# Run all tests ignoring any optional test markers
# Note that paramiko tests will only be enabled if --test-paramiko is also specified
# this is because paramiko is not actively being maintained
skip_if_no_option(
"paramiko", "--test-paramiko", "Use --test-paramiko to run Paramiko tests"
)
return
skip_if_no_option(
"grpc", "--test-grpc", "Use --test-grpc to run gRPC isolation tests"
)
skip_if_no_option(
"paramiko", "--test-paramiko", "Use --test-paramiko to run Paramiko tests"
)