diff options
Diffstat (limited to 'tests/util.py')
-rw-r--r-- | tests/util.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/util.py b/tests/util.py index b81e15b6..cb1a980a 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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): |