Skip to content
Myr

Fixed silent keyword arg to config.from_envvar.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Dave Shawley · committed by Dave Shawley · parent 20a3281 · Browse files · 2 files+19 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−2 removed

  • other:+19 added−2 removed

2 files+19 added−2 removed

modified:flask/testsuite/config.py+18 added
67 unmodified lines
68 self.common_object_test(app)69 finally:70 os.environ = env7172 def test_config_from_envvar_missing(self):73 env = os.environ74 try:75 os.environ = {'FOO_SETTINGS': 'missing.cfg'}76 try:77 app = flask.Flask(__name__)78 app.config.from_envvar('FOO_SETTINGS')79 except IOError, e:80 msg = str(e)81 self.assert_(msg.startswith('[Errno 2] Unable to load configuration '82 'file (No such file or directory):'))83 self.assert_(msg.endswith("missing.cfg'"))84 else:85 self.assert_(0, 'expected config')86 self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))87 finally:88 os.environ = env8990 def test_config_missing(self):91 app = flask.Flask(__name__)92 try:93 app.config.from_pyfile('missing.cfg')
207 unmodified lines
modified:flask/config.py+1 added-2 removed
104 unmodified lines
105 'and as such configuration could not be '106 'loaded. Set this variable and make it '107 'point to a configuration file' %108 variable_name)109 self.from_pyfile(rv)110 return True109 return self.from_pyfile(rv, silent=silent)110111 def from_pyfile(self, filename, silent=False):112 """Updates the values in the config from a Python file. This function113 behaves as if the file was imported as module with the
55 unmodified lines