diff options
author | Georg Brandl <georg@python.org> | 2010-08-21 22:47:18 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-21 22:47:18 +0200 |
commit | 25ff50b600135e3a0bd2ba4faeeb886d1d55fb6a (patch) | |
tree | c02d8c33dab268e7df3d6bd8ff6ed33512e6250b | |
parent | e2dd1506291567ae962745acad1e50fd7c6835d1 (diff) | |
download | sphinx-25ff50b600135e3a0bd2ba4faeeb886d1d55fb6a.tar.gz |
Add skip_if and skip_unless test decorators.
-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): |