@pytest.fixture(scope='session', autouse=True)
def reset_database(request, app):
    db_name = 'test_freight'

    db.session.close_all()

    # 9.1 does not support --if-exists
    if subprocess.call("psql -l | grep '%s'" % db_name, shell=True) == 0:
        engine = db.engine
        engine.connect().close()
        engine.dispose()
        subprocess.check_call('dropdb %s' % db_name, shell=True)

    subprocess.check_call('createdb -E utf-8 %s' % db_name, shell=True)

    command.upgrade(ALEMBIC_CONFIG, 'head')
    return lambda: reset_database(request, app)
dataset/ETHPy150Open getsentry/freight/conftest.py/reset_database/original