Browse Source

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.
pull/415/head
Dave Shawley 13 years ago
parent
commit
76773e1d0a
  1. 3
      flask/config.py
  2. 18
      flask/testsuite/config.py

3
flask/config.py

@ -106,8 +106,7 @@ class Config(dict):
'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

18
flask/testsuite/config.py

@ -69,6 +69,24 @@ class ConfigTestCase(FlaskTestCase):
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:

Loading…
Cancel
Save