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.
This commit is contained in:
Dave Shawley 2012-03-01 08:34:08 -05:00
parent 20a3281209
commit 76773e1d0a
2 changed files with 19 additions and 2 deletions

View file

@ -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: