MCPcopy Create free account
hub / github.com/ipython/ipython / skip_decorator

Function skip_decorator

IPython/testing/decorators.py:188–228  ·  view source on GitHub ↗
(f)

Source from the content-addressed store, hash-verified

186 '''
187
188 def skip_decorator(f):
189 # Local import to avoid a hard nose dependency and only incur the
190 # import time overhead at actual test-time.
191 import nose
192
193 # Allow for both boolean or callable skip conditions.
194 if callable(skip_condition):
195 skip_val = skip_condition
196 else:
197 skip_val = lambda : skip_condition
198
199 def get_msg(func,msg=None):
200 """Skip message with information about function being skipped."""
201 if msg is None: out = 'Test skipped due to test condition.'
202 else: out = msg
203 return "Skipping test: %s. %s" % (func.__name__,out)
204
205 # We need to define *two* skippers because Python doesn't allow both
206 # return with value and yield inside the same function.
207 def skipper_func(*args, **kwargs):
208 """Skipper for normal test functions."""
209 if skip_val():
210 raise nose.SkipTest(get_msg(f,msg))
211 else:
212 return f(*args, **kwargs)
213
214 def skipper_gen(*args, **kwargs):
215 """Skipper for test generators."""
216 if skip_val():
217 raise nose.SkipTest(get_msg(f,msg))
218 else:
219 for x in f(*args, **kwargs):
220 yield x
221
222 # Choose the right skipper to use when building the actual generator.
223 if nose.util.isgenerator(f):
224 skipper = skipper_gen
225 else:
226 skipper = skipper_func
227
228 return nose.tools.make_decorator(f)(skipper)
229
230 return skip_decorator
231

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected