def knownfailureif(fail_condition, msg=None):
if msg is None:<EOL><INDENT>msg = '<STR_LIT>'<EOL><DEDENT>if callable(fail_condition):<EOL><INDENT>fail_val = lambda : fail_condition()<EOL><DEDENT>else:<EOL><INDENT>fail_val = lambda : fail_condition<EOL><DEDENT>def knownfail_decorator(f):<EOL><INDENT>import nose<EOL>def knownfailer(*args, **kwargs):<EOL><INDENT>if fail_val():<EOL><INDENT>raise KnownFailureTest(msg)<EOL><DEDENT>else:<EOL><INDENT>return f(*args, **kwargs)<EOL><DEDENT><DEDENT>return nose.tools.make_decorator(f)(knownfailer)<EOL><DEDENT>return knownfail_decorator<EOL>
Make function raise KnownFailureTest exception if 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
----------
fail_condition : bool or callable
    Flag to determine whether to mark the decorated test as a known
    failure (if True) or not (if False).
msg : str, optional
    Message to give on raising a KnownFailureTest 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.