File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -191,18 +191,17 @@ def get_data(self, file_name):
191191 data = utils .open_json (self .context_dirs , file_name )
192192 elif file_extension in [".yml" , ".yaml" ]:
193193 data = utils .open_yaml (self .context_dirs , file_name )
194- utils .merge (data , self .__cached_environ_variables )
195194 else :
196195 raise exceptions .IncorrectDataInput
196+ utils .merge (data , self .__cached_environ_variables )
197197 return data
198- except Exception as exception :
198+ except ( IOError , exceptions . IncorrectDataInput ) as exception :
199199 # If data file doesn't exist:
200200 # 1. Alert the user of their (potential) mistake
201201 # 2. Attempt to use environment vars as data
202- reporter .report_info_message (str (exception ))
202+ reporter .report_warning_message (str (exception ))
203203 reporter .report_using_env_vars ()
204- data = os .environ
205- return data
204+ return self .__cached_environ_variables
206205
207206
208207def make_sure_all_pkg_are_loaded ():
Original file line number Diff line number Diff line change @@ -18,3 +18,21 @@ def test_environ_variables():
1818 context = Context (os .path .join ("tests" , "fixtures" ))
1919 data = context .get_data ("simple.yaml" )
2020 eq_ (data [test_var ], test_value )
21+
22+
23+ def test_json_data_overrides_environ_variables ():
24+ test_var = "TEST_ENVIRONMENT_VARIABLE"
25+ test_value = "am I found"
26+ os .environ [test_var ] = test_value
27+ context = Context (os .path .join ("tests" , "fixtures" ))
28+ data = context .get_data ("simple.json" )
29+ eq_ (data [test_var ], test_value )
30+
31+
32+ def test_unknown_data_file ():
33+ test_var = "TEST_ENVIRONMENT_VARIABLE"
34+ test_value = "am I found"
35+ os .environ [test_var ] = test_value
36+ context = Context (os .path .join ("tests" , "fixtures" ))
37+ data = context .get_data ("unknown.data" )
38+ eq_ (data [test_var ], test_value )
You can’t perform that action at this time.
0 commit comments