File tree 2 files changed +17
-1
lines changed 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,11 @@ def from_pyfile(self, filename):
116
116
filename = os .path .join (self .root_path , filename )
117
117
d = type (sys )('config' )
118
118
d .__file__ = filename
119
- execfile (filename , d .__dict__ )
119
+ try :
120
+ execfile (filename , d .__dict__ )
121
+ except IOError , e :
122
+ e .strerror = 'Unable to load configuration file (%s)' % e .strerror
123
+ raise
120
124
self .from_object (d )
121
125
122
126
def from_object (self , obj ):
Original file line number Diff line number Diff line change @@ -1018,6 +1018,18 @@ def test_config_from_envvar(self):
1018
1018
finally :
1019
1019
os .environ = env
1020
1020
1021
+ def test_config_missing (self ):
1022
+ app = flask .Flask (__name__ )
1023
+ try :
1024
+ app .config .from_pyfile ('missing.cfg' )
1025
+ except IOError , e :
1026
+ msg = str (e )
1027
+ assert msg .startswith ('[Errno 2] Unable to load configuration '
1028
+ 'file (No such file or directory):' )
1029
+ assert msg .endswith ("missing.cfg'" )
1030
+ else :
1031
+ assert 0 , 'expected config'
1032
+
1021
1033
1022
1034
class SubdomainTestCase (unittest .TestCase ):
1023
1035
You can’t perform that action at this time.
0 commit comments