Skip to content

Commit

Permalink
adding in try around __import__ to catch invalid files/paths (#1950)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt authored and untitaker committed Aug 12, 2016
1 parent e6d7a43 commit 0f1cf50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ def locate_app(app_id):
module = app_id
app_obj = None

__import__(module)
try:
__import__(module)
except ImportError:
raise NoAppException('The file/path provided (%s) does not appear to '
'exist. Please verify the path is correct. If '
'app is not on PYTHONPATH, ensure the extension '
'is .py' % module)
mod = sys.modules[module]
if app_obj is None:
app = find_best_app(mod)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def test_locate_app(test_apps):
assert locate_app("cliapp.app").name == "testapp"
assert locate_app("cliapp.app:testapp").name == "testapp"
assert locate_app("cliapp.multiapp:app1").name == "app1"
pytest.raises(NoAppException, locate_app, "notanpp.py")
pytest.raises(NoAppException, locate_app, "cliapp/app")
pytest.raises(RuntimeError, locate_app, "cliapp.app:notanapp")


Expand Down

0 comments on commit 0f1cf50

Please sign in to comment.