def skipif(skip_condition, msg=None):
def skip_decorator(f):<EOL><INDENT>import nose<EOL>if callable(skip_condition):<EOL><INDENT>skip_val = lambda : skip_condition()<EOL><DEDENT>else:<EOL><INDENT>skip_val = lambda : skip_condition<EOL><DEDENT>def get_msg(func,msg=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if msg is None:<EOL><INDENT>out = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>out = '<STR_LIT:\n>'+msg<EOL><DEDENT>return "<STR_LIT>" % (func.__name__,out)<EOL><DEDENT>def skipper_func(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if skip_val():<EOL><INDENT>raise nose.SkipTest(get_msg(f,msg))<EOL><DEDENT>else:<EOL><INDENT>return f(*args, **kwargs)<EOL><DEDENT><DEDENT>def skipper_gen(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if skip_val():<EOL><INDENT>raise nose.SkipTest(get_msg(f,msg))<EOL><DEDENT>else:<EOL><INDENT>for x in f(*args, **kwargs):<EOL><INDENT>yield x<EOL><DEDENT><DEDENT><DEDENT>if nose.util.isgenerator(f):<EOL><INDENT>skipper = skipper_gen<EOL><DEDENT>else:<EOL><INDENT>skipper = skipper_func<EOL><DEDENT>return nose.tools.make_decorator(f)(skipper)<EOL><DEDENT>return skip_decorator<EOL>
Make function raise SkipTest exception if a given condition is true.

If the condition is a callable, it is used at runtime to dynamically
make the decision. This is useful for tests that may require costly
imports, to delay the cost until the test suite is actually executed.

Parameters
----------
skip_condition : bool or callable
    Flag to determine whether to skip the decorated test.
msg : str, optional
    Message to give on raising a SkipTest exception. Default is None.

Returns
-------
decorator : function
    Decorator which, when applied to a function, causes SkipTest
    to be raised when `skip_condition` is True, and the function
    to be called normally otherwise.

Notes
-----
The decorator itself is decorated with the ``nose.tools.make_decorator``
function in order to transmit function name, and various other metadata.