(f)
| 54 | """ |
| 55 | |
| 56 | def skip_decorator(f): |
| 57 | # Local import to avoid a hard nose dependency and only incur the |
| 58 | # import time overhead at actual test-time. |
| 59 | import nose |
| 60 | |
| 61 | # Allow for both boolean or callable skip conditions. |
| 62 | if callable(skip_condition): |
| 63 | skip_val = lambda : skip_condition() |
| 64 | else: |
| 65 | skip_val = lambda : skip_condition |
| 66 | |
| 67 | def get_msg(func,msg=None): |
| 68 | """Skip message with information about function being skipped.""" |
| 69 | if msg is None: |
| 70 | out = 'Test skipped due to test condition' |
| 71 | else: |
| 72 | out = '\n'+msg |
| 73 | |
| 74 | return "Skipping test: %s%s" % (func.__name__,out) |
| 75 | |
| 76 | # We need to define *two* skippers because Python doesn't allow both |
| 77 | # return with value and yield inside the same function. |
| 78 | def skipper_func(*args, **kwargs): |
| 79 | """Skipper for normal test functions.""" |
| 80 | if skip_val(): |
| 81 | raise nose.SkipTest(get_msg(f,msg)) |
| 82 | else: |
| 83 | return f(*args, **kwargs) |
| 84 | |
| 85 | def skipper_gen(*args, **kwargs): |
| 86 | """Skipper for test generators.""" |
| 87 | if skip_val(): |
| 88 | raise nose.SkipTest(get_msg(f,msg)) |
| 89 | else: |
| 90 | for x in f(*args, **kwargs): |
| 91 | yield x |
| 92 | |
| 93 | # Choose the right skipper to use when building the actual decorator. |
| 94 | if nose.util.isgenerator(f): |
| 95 | skipper = skipper_gen |
| 96 | else: |
| 97 | skipper = skipper_func |
| 98 | |
| 99 | return nose.tools.make_decorator(f)(skipper) |
| 100 | |
| 101 | return skip_decorator |
| 102 |
nothing calls this directly
no outgoing calls
no test coverage detected