def manager(manager_setup, test_db_args, test_db_database):
    test_db_args['database'] = test_db_database
    m = sql_lock.SQLLockManager('test').connect(**test_db_args)

    with m._db_conn() as conn:
        conn.query('DELETE FROM %s' % m.table_name)

    return m
def manager_setup(request, test_db_args, test_db_database):
    with database.connect(**test_db_args) as conn:
        conn.execute('CREATE DATABASE IF NOT EXISTS %s' % test_db_database)

    test_db_args['database'] = test_db_database
    q = sql_lock.SQLLockManager('test').connect(**test_db_args).setup()

    def cleanup():
        q.destroy()

    request.addfinalizer(cleanup)
def test_ensure_connected():
    q = sql_lock.SQLLockManager('bad_manager')

    with pytest.raises(exceptions.NotConnected):
        q.acquire('asdf')