@@ -60,6 +60,9 @@ class Distro:
60
60
"ocsp" ,
61
61
]
62
62
63
+ # Mapping of env variables to options
64
+ OPTION_TO_ENV_VAR = {"cov" : "COVERAGE" , "crypt_shared" : "TEST_CRYPT_SHARED" }
65
+
63
66
64
67
def get_test_options (
65
68
description , require_sub_test_name = True , allow_extra_opts = False
@@ -94,6 +97,9 @@ def get_test_options(
94
97
)
95
98
parser .add_argument ("--auth" , action = "store_true" , help = "Whether to add authentication." )
96
99
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
+ )
97
103
98
104
# Add the test modifiers.
99
105
if require_sub_test_name :
@@ -121,35 +127,51 @@ def get_test_options(
121
127
parser .add_argument (
122
128
"--disable-test-commands" , action = "store_true" , help = "Disable test commands."
123
129
)
124
- parser .add_argument (
125
- "--test-min-deps" , action = "store_true" , help = "Test against minimum dependency versions"
126
- )
127
130
128
131
# Get the options.
129
132
if not allow_extra_opts :
130
133
opts , extra_opts = parser .parse_args (), []
131
134
else :
132
135
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 )
137
136
138
137
# Handle validation and environment variable overrides.
139
138
test_name = opts .test_name
140
139
sub_test_name = opts .sub_test_name if require_sub_test_name else ""
141
140
if require_sub_test_name and test_name in SUB_TEST_REQUIRED and not sub_test_name :
142
141
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 :
144
144
opts .auth = True
145
145
# 'auth_aws ecs' shouldn't have extra auth set.
146
146
if test_name == "auth_aws" and sub_test_name == "ecs" :
147
147
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 )
150
152
return opts , extra_opts
151
153
152
154
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
+
153
175
def read_env (path : Path | str ) -> dict [str , str ]:
154
176
config = dict ()
155
177
with Path (path ).open () as fid :
0 commit comments