Import app from wsgi.py or app.py if FLASK_APP is not defined

Fixes #2376
This commit is contained in:
Miguel Grinberg 2017-06-15 11:27:50 -07:00
parent d625d41104
commit 7c40aa9e50
No known key found for this signature in database
GPG key ID: 36848B262DF5F06C
4 changed files with 48 additions and 10 deletions

View file

@ -181,6 +181,8 @@ def test_locate_app(test_apps):
script_info, "cliapp.factory:create_app ()")
pytest.raises(
NoAppException, locate_app, script_info, "cliapp.importerrorapp")
assert locate_app(script_info, "notanpp.py",
raise_if_not_found=False) is None
def test_find_default_import_path(test_apps, monkeypatch, tmpdir):
@ -214,7 +216,7 @@ def test_get_version(test_apps, capsys):
assert py_ver in out
def test_scriptinfo(test_apps):
def test_scriptinfo(test_apps, monkeypatch):
"""Test of ScriptInfo."""
obj = ScriptInfo(app_import_path="cliapp.app:testapp")
assert obj.load_app().name == "testapp"
@ -228,6 +230,24 @@ def test_scriptinfo(test_apps):
assert app.name == "createapp"
assert obj.load_app() == app
obj = ScriptInfo()
pytest.raises(
NoAppException, obj.load_app)
# import app from wsgi.py in current directory
monkeypatch.chdir(os.path.abspath(
os.path.join(os.path.dirname(__file__), 'test_apps', 'helloworld')))
obj = ScriptInfo()
app = obj.load_app()
assert app.name == 'hello'
# import app from app.py in current directory
monkeypatch.chdir(os.path.abspath(
os.path.join(os.path.dirname(__file__), 'test_apps', 'cliapp')))
obj = ScriptInfo()
app = obj.load_app()
assert app.name == 'testapp'
def test_with_appcontext(runner):
"""Test of with_appcontext."""