@@ -52,18 +52,31 @@ class Distro:
5252SUB_TEST_REQUIRED = ["auth_aws" , "kms" ]
5353
5454
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 ]]:
5658 parser = argparse .ArgumentParser (
57- description = __doc__ , formatter_class = argparse .RawDescriptionHelpFormatter
59+ description = description , formatter_class = argparse .RawDescriptionHelpFormatter
5860 )
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+ )
6780 parser .add_argument (
6881 "--verbose" , "-v" , action = "store_true" , help = "Whether to log at the DEBUG level"
6982 )
@@ -73,15 +86,18 @@ def get_test_options(require_sub_test_name=True):
7386 parser .add_argument ("--auth" , action = "store_true" , help = "Whether to add authentication" )
7487 parser .add_argument ("--ssl" , action = "store_true" , help = "Whether to add TLS configuration" )
7588 # 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 ()
7793 if opts .verbose :
7894 LOGGER .setLevel (logging .DEBUG )
7995 elif opts .quiet :
8096 LOGGER .setLevel (logging .WARNING )
8197
8298 # Handle validation and environment variable overrides.
8399 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 ""
85101 if require_sub_test_name and test_name in SUB_TEST_REQUIRED and not sub_test_name :
86102 raise ValueError (f"Test '{ test_name } ' requires a sub_test_name" )
87103 if "auth" in test_name or os .environ .get ("AUTH" ) == "auth" :
@@ -91,7 +107,7 @@ def get_test_options(require_sub_test_name=True):
91107 opts .auth = False
92108 if os .environ .get ("SSL" ) == "ssl" :
93109 opts .ssl = True
94- return opts
110+ return opts , extra_opts
95111
96112
97113def read_env (path : Path | str ) -> dict [str , Any ]:
@@ -115,8 +131,10 @@ def write_env(name: str, value: Any = "1") -> None:
115131 fid .write (f'export { name } ="{ value } "\n ' )
116132
117133
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 )
120138 kwargs .setdefault ("check" , True )
121139 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