def migration(request): """ Runs migrations before all tests and delete database at the end. """ api, app = app_factory() with app.app_context(): remove_test_db() run_migrations() request.addfinalizer(app_context(remove_test_db))
def test_run_migrations_and_class_import(monkeypatch): paths = [] def mock__run(path): paths.append(path) monkeypatch.setattr(runner, '_run_migration', mock__run) runner.run_migrations() assert len(paths) != 0 migration_class = runner._import_migration_class(paths[0]) assert issubclass(migration_class, base.Migration)
def remove_existing_database(func: Callable, *args, **kwargs): with current_app().app_context(): remove_test_db() try: output = func(*args, **kwargs) except Exception as e: raise e finally: run_migrations() return output
def migrate(): print('Running migrations') run_migrations() print('DONE')