import unittest


def requires_attr(obj, attr):
    """Decorator used to skip tests if an object does not have the required
    attribute.
    """

    try:
        getattr(obj, attr)
        return lambda func: func
    except AttributeError:
        return unittest.skip('Required attribute "{}" not found on {}'.format(
            attr, obj))