diff --git a/tests/test_cli.py b/tests/test_cli.py index c4be45e6..4a3d0831 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -21,7 +21,8 @@ from click.testing import CliRunner from flask import Flask, current_app from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \ - find_best_app, locate_app, with_appcontext, prepare_exec_for_file + find_best_app, locate_app, with_appcontext, prepare_exec_for_file, \ + find_default_import_path def test_cli_name(test_apps): @@ -79,6 +80,19 @@ def test_locate_app(test_apps): pytest.raises(RuntimeError, locate_app, "cliapp.app:notanapp") +def test_find_default_import_path(test_apps, monkeypatch, tmpdir): + """Test of find_default_import_path.""" + monkeypatch.delitem(os.environ, 'FLASK_APP', raising=False) + assert find_default_import_path() == None + monkeypatch.setitem(os.environ, 'FLASK_APP', 'notanapp') + assert find_default_import_path() == 'notanapp' + tmpfile = tmpdir.join('testapp.py') + tmpfile.write('') + monkeypatch.setitem(os.environ, 'FLASK_APP', str(tmpfile)) + expect_rv = prepare_exec_for_file(str(tmpfile)) + assert find_default_import_path() == expect_rv + + def test_scriptinfo(test_apps): """Test of ScriptInfo.""" obj = ScriptInfo(app_import_path="cliapp.app:testapp")