From b92391d177e3abb322e31646870abac46a1f6276 Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Mon, 17 Feb 2020 23:51:06 -0800 Subject: [PATCH] Switch to Flask's native CLI Drop `flask_script` in favor of Flask's native CLI: * https://flask.palletsprojects.com/en/master/cli/ This also requires changing the tests so that `pytest` mocks the env var `FLASK_ENV` so that the test app starts in development mode. Unlike normal test apps, we _do_ want development/debug mode, in addition to testing mode. --- example/{example.py => app.py} | 9 ++------- test/basic_app.py | 5 ----- test/conftest.py | 5 +++++ 3 files changed, 7 insertions(+), 12 deletions(-) rename example/{example.py => app.py} (89%) create mode 100644 test/conftest.py diff --git a/example/example.py b/example/app.py similarity index 89% rename from example/example.py rename to example/app.py index 8ea9e46..a758d44 100644 --- a/example/example.py +++ b/example/app.py @@ -1,8 +1,6 @@ -import sys -sys.path.insert(0, '.') +# Run using: `FLASK_ENV=development flask run` from flask import Flask, render_template, redirect, url_for -from flask_script import Manager from flask_sqlalchemy import SQLAlchemy from flask_debugtoolbar import DebugToolbarExtension @@ -16,7 +14,6 @@ #) #app.config['DEBUG_TB_HOSTS'] = ('127.0.0.1', '::1' ) app.config['SECRET_KEY'] = 'asd' -app.config['DEBUG'] = True # TODO: This can be removed once flask_sqlalchemy 3.0 ships app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False @@ -46,8 +43,6 @@ def redirect_example(): response.set_cookie('test_cookie', '1') return response + if __name__ == "__main__": db.create_all() - - manager = Manager(app) - manager.run() diff --git a/test/basic_app.py b/test/basic_app.py index beb2c32..085bf6c 100644 --- a/test/basic_app.py +++ b/test/basic_app.py @@ -5,7 +5,6 @@ app = Flask('basic_app') -app.debug = True app.config['SECRET_KEY'] = 'abc123' # TODO: This can be removed once flask_sqlalchemy 3.0 ships @@ -29,7 +28,3 @@ def index(): db.create_all() Foo.query.filter_by(id=1).all() return render_template('basic_app.html') - - -if __name__ == '__main__': - app.run() diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..e9dc5b8 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,5 @@ +import pytest + +@pytest.fixture(autouse=True) +def mock_env_development(monkeypatch): + monkeypatch.setenv("FLASK_ENV", "development")