@@ -52,18 +52,31 @@ class Distro:
52
52
SUB_TEST_REQUIRED = ["auth_aws" , "kms" ]
53
53
54
54
55
- def get_test_options (require_sub_test_name = True ):
55
+ def get_test_options (
56
+ description , require_sub_test_name = True , allow_extra_opts = False
57
+ ) -> tuple [argparse .Namespace , list [str ]]:
56
58
parser = argparse .ArgumentParser (
57
- description = __doc__ , formatter_class = argparse .RawDescriptionHelpFormatter
59
+ description = description , formatter_class = argparse .RawDescriptionHelpFormatter
58
60
)
59
- parser .add_argument (
60
- "test_name" ,
61
- choices = sorted (TEST_SUITE_MAP ),
62
- nargs = "?" ,
63
- default = "default" ,
64
- help = "The name of the test suite to set up, typically the same name as a pytest marker." ,
65
- )
66
- parser .add_argument ("sub_test_name" , nargs = "?" , help = "The sub test name, for example 'azure'" )
61
+ if require_sub_test_name :
62
+ parser .add_argument (
63
+ "test_name" ,
64
+ choices = sorted (TEST_SUITE_MAP ),
65
+ nargs = "?" ,
66
+ default = "default" ,
67
+ help = "The optional name of the test suite to set up, typically the same name as a pytest marker." ,
68
+ )
69
+ parser .add_argument (
70
+ "sub_test_name" , nargs = "?" , help = "The optional sub test name, for example 'azure'."
71
+ )
72
+ else :
73
+ parser .add_argument (
74
+ "test_name" ,
75
+ choices = sorted (TEST_SUITE_MAP ),
76
+ nargs = "?" ,
77
+ default = "default" ,
78
+ help = "The optional name of the test suite to be run, which informs the server configuration." ,
79
+ )
67
80
parser .add_argument (
68
81
"--verbose" , "-v" , action = "store_true" , help = "Whether to log at the DEBUG level"
69
82
)
@@ -73,15 +86,18 @@ def get_test_options(require_sub_test_name=True):
73
86
parser .add_argument ("--auth" , action = "store_true" , help = "Whether to add authentication" )
74
87
parser .add_argument ("--ssl" , action = "store_true" , help = "Whether to add TLS configuration" )
75
88
# Get the options.
76
- opts = parser .parse_args ()
89
+ if not allow_extra_opts :
90
+ opts , extra_opts = parser .parse_args (), []
91
+ else :
92
+ opts , extra_opts = parser .parse_known_args ()
77
93
if opts .verbose :
78
94
LOGGER .setLevel (logging .DEBUG )
79
95
elif opts .quiet :
80
96
LOGGER .setLevel (logging .WARNING )
81
97
82
98
# Handle validation and environment variable overrides.
83
99
test_name = opts .test_name
84
- sub_test_name = opts .sub_test_name
100
+ sub_test_name = opts .sub_test_name if require_sub_test_name else ""
85
101
if require_sub_test_name and test_name in SUB_TEST_REQUIRED and not sub_test_name :
86
102
raise ValueError (f"Test '{ test_name } ' requires a sub_test_name" )
87
103
if "auth" in test_name or os .environ .get ("AUTH" ) == "auth" :
@@ -91,7 +107,7 @@ def get_test_options(require_sub_test_name=True):
91
107
opts .auth = False
92
108
if os .environ .get ("SSL" ) == "ssl" :
93
109
opts .ssl = True
94
- return opts
110
+ return opts , extra_opts
95
111
96
112
97
113
def read_env (path : Path | str ) -> dict [str , Any ]:
@@ -115,8 +131,10 @@ def write_env(name: str, value: Any = "1") -> None:
115
131
fid .write (f'export { name } ="{ value } "\n ' )
116
132
117
133
118
- def run_command (cmd : str , ** kwargs : Any ) -> None :
119
- LOGGER .info ("Running command %s..." , cmd )
134
+ def run_command (cmd : str | list [str ], ** kwargs : Any ) -> None :
135
+ if isinstance (cmd , list ):
136
+ cmd = " " .join (cmd )
137
+ LOGGER .info ("Running command '%s'..." , cmd )
120
138
kwargs .setdefault ("check" , True )
121
139
subprocess .run (shlex .split (cmd ), ** kwargs ) # noqa: PLW1510, S603
122
- LOGGER .info ("Running command %s ... done." , cmd )
140
+ LOGGER .info ("Running command '%s' ... done." , cmd )
0 commit comments