import os import pytest from the_works import create_app from the_works.database import db as _db from the_works.models import Genre # set app mode to testing via environment variable os.environ["FLASK_APP_MODE"] = "testing" @pytest.fixture() def _app(): _app = create_app() # other setup can go here context = _app.app_context() context.push() yield _app # clean up / reset resources here context.pop() @pytest.fixture(scope="function") def db(_app): with _app.app_context(): _db.session.add(Genre(ID=1, Genre="spam")) _db.session.add(Genre(ID=2, Genre="eggs")) _db.session.commit() yield _db _db.drop_all() _db.create_all() @pytest.fixture() def client(_app): return _app.test_client() @pytest.fixture() def runner(_app): return _app.test_cli_runner()