Skip to content
Myr

adding in try around __import__ to catch invalid files/paths (#1950)

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

authored by Nate Prewitt · committed by Markus Unterwaditzer · parent e6d7a43 · Browse files · 2 files+9 added−1 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+9 added−1 removed

  • tests:+2 added−0 removed
  • other:+7 added−1 removed

2 files+9 added−1 removed

modified:flask/cli.py+7 added-1 removed
84 unmodified lines
85 else:86 module = app_id87 app_obj = None8889 try:89 __import__(module)90 __import__(module)91 except ImportError:92 raise NoAppException('The file/path provided (%s) does not appear to '93 'exist. Please verify the path is correct. If '94 'app is not on PYTHONPATH, ensure the extension '95 'is .py' % module)96 mod = sys.modules[module]97 if app_obj is None:98 app = find_best_app(mod)99 else:
413 unmodified lines
modified:tests/test_cli.py+2 added
78 unmodified lines
79 """Test of locate_app."""80 assert locate_app("cliapp.app").name == "testapp"81 assert locate_app("cliapp.app:testapp").name == "testapp"82 assert locate_app("cliapp.multiapp:app1").name == "app1"83 pytest.raises(NoAppException, locate_app, "notanpp.py")84 pytest.raises(NoAppException, locate_app, "cliapp/app")85 pytest.raises(RuntimeError, locate_app, "cliapp.app:notanapp")868788def test_find_default_import_path(test_apps, monkeypatch, tmpdir):
89 unmodified lines