Permalink
Browse files

Fixed silent keyword arg to config.from_envvar.

The ``silent`` keyword argument to Config.from_envvar was not being honored
if the environment variable existed but the file that it mentioned did not.
The fix was simple - pass the keyword argument on to the underlying call to
``from_pyfile``.  I also noticed that the return value from ``from_pyfile``
was not being passed back so I fixed that as well.
  • Loading branch information...
1 parent 20a3281 commit 76773e1d0a8cabbe048bb76f9306185e9d83a85c @dave-shawley dave-shawley committed Mar 1, 2012
Showing with 19 additions and 2 deletions.
  1. +1 −2 flask/config.py
  2. +18 −0 flask/testsuite/config.py
View
@@ -106,8 +106,7 @@ def from_envvar(self, variable_name, silent=False):
'loaded. Set this variable and make it '
'point to a configuration file' %
variable_name)
- self.from_pyfile(rv)
- return True
+ return self.from_pyfile(rv, silent=silent)
def from_pyfile(self, filename, silent=False):
"""Updates the values in the config from a Python file. This function
View
@@ -69,6 +69,24 @@ def test_config_from_envvar(self):
finally:
os.environ = env
+ def test_config_from_envvar_missing(self):
+ env = os.environ
+ try:
+ os.environ = {'FOO_SETTINGS': 'missing.cfg'}
+ try:
+ app = flask.Flask(__name__)
+ app.config.from_envvar('FOO_SETTINGS')
+ except IOError, e:
+ msg = str(e)
+ self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
+ 'file (No such file or directory):'))
+ self.assert_(msg.endswith("missing.cfg'"))
+ else:
+ self.assert_(0, 'expected config')
+ self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))
+ finally:
+ os.environ = env
+
def test_config_missing(self):
app = flask.Flask(__name__)
try:

0 comments on commit 76773e1

Please sign in to comment.