These are chat archives for pythonvietnam/Flask

12th
Jul 2017
Jacek BroĊ„ski-Jankowski
@jacol12345
Jul 12 2017 12:57

Hi, anyone succeeded on running Alembic upgrade() in pytest fixture with SQLite in-memory DB?

@pytest.fixture()
def app():
    """An application for the tests."""
    _app = create_app(TestConfig)
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()


@pytest.fixture
def db(request, app):
    _db.app = app
    with app.app_context():
        from flask_migrate import upgrade
        upgrade(directory=TestConfig.ALEMBIC_DIR)

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()

I checked with pdb that alembic script is being executed but those changes are not reflected in tests. Using _db.create_all() works but I need to perform migrations in tests as they contain data upgrades. Help appreciated!

I'd prefer a cleaner solution than proposed here: https://gist.github.com/alexmic/7857543