conftest.py 531 Bytes
import pytest

from flaskr import create_app
from flaskr.models import db, User


@pytest.fixture()
def testapp(request):
    app = create_app('flaskr.settings.TestConfig')
    client = app.test_client()

    db.app = app
    db.create_all()

    if getattr(request.module, "create_user", True):
        admin = User('admin', 'supersafepassword')
        db.session.add(admin)
        db.session.commit()

    def teardown():
        db.session.remove()
        db.drop_all()

    request.addfinalizer(teardown)

    return client