Add skip_if and skip_unless test decorators.

This commit is contained in:
Georg Brandl
2010-08-21 22:47:18 +02:00
parent 2399e4627c
commit bcf84166ca

View File

@@ -25,12 +25,12 @@ from sphinx.ext.autodoc import AutoDirective
from path import path
from nose import tools
from nose import tools, SkipTest
__all__ = [
'test_root',
'raises', 'raises_msg', 'Struct',
'raises', 'raises_msg', 'skip_if', 'skip_unless', 'Struct',
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
'path', 'with_tempdir', 'write_file',
'sprint', 'remove_unicode_literals',
@@ -71,6 +71,21 @@ def raises_msg(exc, msg, func, *args, **kwds):
raise AssertionError('%s did not raise %s' %
(func.__name__, _excstr(exc)))
def skip_if(condition, msg=None):
"""Decorator to skip test if condition is true."""
def deco(test):
@tools.make_decorator(test)
def skipper(*args, **kwds):
if condition:
raise SkipTest(msg or 'conditional skip')
return test(*args, **kwds)
return skipper
return deco
def skip_unless(condition, msg=None):
"""Decorator to skip test if condition is false."""
return skip_if(not condition, msg)
class Struct(object):
def __init__(self, **kwds):