Merge pull request #2297 from HndrkMkt/#2265-auto-detect-create-app-function

Auto-detect create_app() in find_best_app() #2265
This commit is contained in:
David Lord 2017-05-22 16:13:27 -07:00 committed by GitHub
commit 0c94908956
3 changed files with 72 additions and 8 deletions

View file

@ -51,6 +51,34 @@ def test_find_best_app(test_apps):
myapp = Flask('appname')
assert find_best_app(Module) == Module.myapp
class Module:
@staticmethod
def create_app():
return Flask('appname')
assert isinstance(find_best_app(Module), Flask)
assert find_best_app(Module).name == 'appname'
class Module:
@staticmethod
def make_app():
return Flask('appname')
assert isinstance(find_best_app(Module), Flask)
assert find_best_app(Module).name == 'appname'
class Module:
myapp = Flask('appname1')
@staticmethod
def create_app():
return Flask('appname2')
assert find_best_app(Module) == Module.myapp
class Module:
myapp = Flask('appname1')
@staticmethod
def create_app(foo):
return Flask('appname2')
assert find_best_app(Module) == Module.myapp
class Module:
pass
pytest.raises(NoAppException, find_best_app, Module)
@ -60,6 +88,12 @@ def test_find_best_app(test_apps):
myapp2 = Flask('appname2')
pytest.raises(NoAppException, find_best_app, Module)
class Module:
@staticmethod
def create_app(foo):
return Flask('appname2')
pytest.raises(NoAppException, find_best_app, Module)
def test_prepare_exec_for_file(test_apps):
"""Expect the correct path to be set and the correct module name to be returned.