def test_client(): """ This code are originally covered from this blog post: https://www.patricksoftwareblog.com/testing-a-flask-application-using-pytest/ GitLab Repo: https://gitlab.com/patkennedy79/flask_user_management_example/blob/master/tests/conftest.py :return: """ flask_app = server.create_app('flask_test.cfg') # Flask provides a way to test your application by exposing the Werkzeug test Client # and handling the context locals for you. testing_client = flask_app.test_client() # Establish an application context before running the tests. ctx = flask_app.app_context() ctx.push() yield testing_client # this is where the testing happens! ctx.pop()
from src.server import create_app APP = create_app() if __name__ == '__main__': APP.run(host="0.0.0.0")
# entry point for uWSGI from src.server import create_app app = create_app()
def app(): return testing.TestClient(server.create_app())
def app(mocker): app = server.create_app() return app
import os from flask_script import Manager, Shell, Server from src.server import create_app from termcolor import colored app = create_app(os.getenv('APP_STAGE') or 'dev') manager = Manager(app) def make_shell_context(): return dict(app=app) @manager.command def run_tests(): """Run the unit tests.""" import unittest path_to_tests = os.path.join( os.getcwd(), "tests" ) tests = unittest.TestLoader().discover(path_to_tests) unittest.TextTestRunner(verbosity=2).run(tests) @manager.command def clear_db(): from src.api.models import Itinerarie Itinerarie.objects.delete()
def test_client(): """ Generate test client instance for Flask server. """ return create_app().test_client()
from src.server import create_app if __name__ == '__main__': create_app().run()
try: from src.server import create_app except: from server import create_app application = create_app() application.debug = True
def client(): app = create_app('test') app.testing = True return app.test_client()
def test_client(): server = create_app() testing_client = server.test_client() yield testing_client