def db_connect(method):
@functools.wraps(method)<EOL>def wrapped(self, *args, **kwargs):<EOL><INDENT>connect = db_connection_factory()<EOL>with connect() as db_connection:<EOL><INDENT>with db_connection.cursor() as cursor:<EOL><INDENT>return method(self, cursor, *args, **kwargs)<EOL><DEDENT><DEDENT><DEDENT>return wrapped<EOL>
Decorator for methods that need to use the database

    Example:
    @db_connect
    def setUp(self, cursor):
        cursor.execute(some_sql)
        # some other code