import unittest


def _skip_if(condition, reason):
    """Wrapper around unittest.skipIf, if available. If not, do not run test
    when condition is True. unittest.skipIf was not added until python
    2.7. Chapel testing requires python 2.6 support.
    """
    if hasattr(unittest, 'skipIf'):
        return unittest.skipIf(condition, reason)
    elif condition:
        # Skip the test by instead running a noop function that just print a
        # message.
        def skip_it(func):
            def noop(*args, **kwargs):
                print('Skipping "{0}" because: {1}'.format(func.__name__, reason))
            return noop
        return skip_it
    else:
        # Run the test by simply returning the original test function.
        def pass_thru(func):
            return func
        return pass_thru