mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add skip_if and skip_unless test decorators.
This commit is contained in:
@@ -25,12 +25,12 @@ from sphinx.ext.autodoc import AutoDirective
|
|||||||
|
|
||||||
from path import path
|
from path import path
|
||||||
|
|
||||||
from nose import tools
|
from nose import tools, SkipTest
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'test_root',
|
'test_root',
|
||||||
'raises', 'raises_msg', 'Struct',
|
'raises', 'raises_msg', 'skip_if', 'skip_unless', 'Struct',
|
||||||
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
|
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
|
||||||
'path', 'with_tempdir', 'write_file',
|
'path', 'with_tempdir', 'write_file',
|
||||||
'sprint', 'remove_unicode_literals',
|
'sprint', 'remove_unicode_literals',
|
||||||
@@ -71,6 +71,21 @@ def raises_msg(exc, msg, func, *args, **kwds):
|
|||||||
raise AssertionError('%s did not raise %s' %
|
raise AssertionError('%s did not raise %s' %
|
||||||
(func.__name__, _excstr(exc)))
|
(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):
|
class Struct(object):
|
||||||
def __init__(self, **kwds):
|
def __init__(self, **kwds):
|
||||||
|
|||||||
Reference in New Issue
Block a user