Permalink
Browse files

Improved error message for configuration files

  • Loading branch information...
1 parent ed1b34c commit 778e44e39eb42ff6cbee376ce40d1a52a25cb0ce @mitsuhiko mitsuhiko committed Jul 29, 2010
Showing with 17 additions and 1 deletion.
  1. +5 −1 flask/config.py
  2. +12 −0 tests/flask_tests.py
View
@@ -116,7 +116,11 @@ def from_pyfile(self, filename):
filename = os.path.join(self.root_path, filename)
d = type(sys)('config')
d.__file__ = filename
- execfile(filename, d.__dict__)
+ try:
+ execfile(filename, d.__dict__)
+ except IOError, e:
+ e.strerror = 'Unable to load configuration file (%s)' % e.strerror
+ raise
self.from_object(d)
def from_object(self, obj):
View
@@ -1018,6 +1018,18 @@ def test_config_from_envvar(self):
finally:
os.environ = env
+ def test_config_missing(self):
+ app = flask.Flask(__name__)
+ try:
+ app.config.from_pyfile('missing.cfg')
+ except IOError, e:
+ msg = str(e)
+ assert msg.startswith('[Errno 2] Unable to load configuration '
+ 'file (No such file or directory):')
+ assert msg.endswith("missing.cfg'")
+ else:
+ assert 0, 'expected config'
+
class SubdomainTestCase(unittest.TestCase):

0 comments on commit 778e44e

Please sign in to comment.