@@ -75,13 +75,13 @@ def pytest_addoption(parser):
75
75
parser .addini ('django_find_project' ,
76
76
'Automatically find and add a Django project to the '
77
77
'Python path.' ,
78
- default = True )
78
+ type = 'bool' , default = True )
79
79
group ._addoption ('--fail-on-template-vars' ,
80
80
action = 'store_true' , dest = 'itv' , default = False ,
81
81
help = 'Fail for invalid variables in templates.' )
82
82
parser .addini (INVALID_TEMPLATE_VARS_ENV ,
83
83
'Fail for invalid variables in templates.' ,
84
- default = False )
84
+ type = 'bool' , default = False )
85
85
86
86
87
87
def _exists (path , ignore = EnvironmentError ):
@@ -149,22 +149,21 @@ def _setup_django():
149
149
_blocking_manager .disable_database_access ()
150
150
151
151
152
- def _parse_django_find_project_ini (x ):
152
+ def _get_boolean_value (x , name , default = None ):
153
+ if x is None :
154
+ return default
153
155
if x in (True , False ):
154
156
return x
155
-
156
- x = x .lower ()
157
157
possible_values = {'true' : True ,
158
158
'false' : False ,
159
159
'1' : True ,
160
160
'0' : False }
161
-
162
161
try :
163
- return possible_values [x ]
162
+ return possible_values [x . lower () ]
164
163
except KeyError :
165
- raise ValueError ('%s is not a valid value for django_find_project . '
166
- 'It must be one of %s .'
167
- % (x , ', ' .join (possible_values .keys ())))
164
+ raise ValueError ('{} is not a valid value for {} . '
165
+ 'It must be one of {} .'
166
+ % (x , name , ', ' .join (possible_values .keys ())))
168
167
169
168
170
169
def pytest_load_initial_conftests (early_config , parser , args ):
@@ -187,20 +186,18 @@ def pytest_load_initial_conftests(early_config, parser, args):
187
186
if options .version or options .help :
188
187
return
189
188
190
- django_find_project = _parse_django_find_project_ini (
191
- early_config .getini ('django_find_project' ))
189
+ django_find_project = _get_boolean_value (
190
+ early_config .getini ('django_find_project' ), 'django_find_project' )
192
191
193
192
if django_find_project :
194
193
_django_project_scan_outcome = _add_django_project_to_path (args )
195
194
else :
196
195
_django_project_scan_outcome = PROJECT_SCAN_DISABLED
197
196
198
- # Configure FAIL_INVALID_TEMPLATE_VARS
199
- itv = (options .itv or
200
- os .environ .get (INVALID_TEMPLATE_VARS_ENV ) in ['true' , 'True' , '1' ] or
201
- early_config .getini (INVALID_TEMPLATE_VARS_ENV ))
202
-
203
- if itv :
197
+ if (options .itv or
198
+ _get_boolean_value (os .environ .get (INVALID_TEMPLATE_VARS_ENV ),
199
+ INVALID_TEMPLATE_VARS_ENV ) or
200
+ early_config .getini (INVALID_TEMPLATE_VARS_ENV )):
204
201
os .environ [INVALID_TEMPLATE_VARS_ENV ] = 'true'
205
202
206
203
# Configure DJANGO_SETTINGS_MODULE
0 commit comments