@@ -60,6 +60,9 @@ class Distro:
6060 "ocsp" ,
6161]
6262
63+ # Mapping of env variables to options
64+ OPTION_TO_ENV_VAR = {"cov" : "COVERAGE" , "crypt_shared" : "TEST_CRYPT_SHARED" }
65+
6366
6467def get_test_options (
6568 description , require_sub_test_name = True , allow_extra_opts = False
@@ -94,6 +97,9 @@ def get_test_options(
9497 )
9598 parser .add_argument ("--auth" , action = "store_true" , help = "Whether to add authentication." )
9699 parser .add_argument ("--ssl" , action = "store_true" , help = "Whether to add TLS configuration." )
100+ parser .add_argument (
101+ "--test-min-deps" , action = "store_true" , help = "Test against minimum dependency versions"
102+ )
97103
98104 # Add the test modifiers.
99105 if require_sub_test_name :
@@ -121,35 +127,51 @@ def get_test_options(
121127 parser .add_argument (
122128 "--disable-test-commands" , action = "store_true" , help = "Disable test commands."
123129 )
124- parser .add_argument (
125- "--test-min-deps" , action = "store_true" , help = "Test against minimum dependency versions"
126- )
127130
128131 # Get the options.
129132 if not allow_extra_opts :
130133 opts , extra_opts = parser .parse_args (), []
131134 else :
132135 opts , extra_opts = parser .parse_known_args ()
133- if opts .verbose :
134- LOGGER .setLevel (logging .DEBUG )
135- elif opts .quiet :
136- LOGGER .setLevel (logging .WARNING )
137136
138137 # Handle validation and environment variable overrides.
139138 test_name = opts .test_name
140139 sub_test_name = opts .sub_test_name if require_sub_test_name else ""
141140 if require_sub_test_name and test_name in SUB_TEST_REQUIRED and not sub_test_name :
142141 raise ValueError (f"Test '{ test_name } ' requires a sub_test_name" )
143- if "auth" in test_name or os .environ .get ("AUTH" ) == "auth" :
142+ handle_env_overrides (opts )
143+ if "auth" in test_name :
144144 opts .auth = True
145145 # 'auth_aws ecs' shouldn't have extra auth set.
146146 if test_name == "auth_aws" and sub_test_name == "ecs" :
147147 opts .auth = False
148- if os .environ .get ("SSL" ) == "ssl" :
149- opts .ssl = True
148+ if opts .verbose :
149+ LOGGER .setLevel (logging .DEBUG )
150+ elif opts .quiet :
151+ LOGGER .setLevel (logging .WARNING )
150152 return opts , extra_opts
151153
152154
155+ def handle_env_overrides (opts : argparse .Namespace ) -> None :
156+ # Get the options, and then allow environment variable overrides.
157+ for key in vars (opts ):
158+ if key in OPTION_TO_ENV_VAR :
159+ env_var = OPTION_TO_ENV_VAR [key ]
160+ else :
161+ env_var = key .upper ()
162+ if env_var in os .environ :
163+ if env_var == "AUTH" :
164+ opts .auth = os .environ .get ("AUTH" ) == "auth"
165+ elif env_var == "SSL" :
166+ ssl_opt = os .environ .get ("SSL" , "" )
167+ opts .ssl = ssl_opt and ssl_opt .lower () != "nossl"
168+ elif isinstance (getattr (opts , key ), bool ):
169+ if os .environ [env_var ]:
170+ setattr (opts , key , True )
171+ else :
172+ setattr (opts , key , os .environ [env_var ])
173+
174+
153175def read_env (path : Path | str ) -> dict [str , str ]:
154176 config = dict ()
155177 with Path (path ).open () as fid :
0 commit comments