module documentation

Decorators for labeling and modifying behavior of test objects.

Decorators that merely return a modified version of the original function object are straightforward. Decorators that return a new function object need to use

nose.tools.make_decorator(original_function)(decorator)

in returning the decorator, in order to preserve meta-data such as function name, setup and teardown functions and so on - see nose.tools for more information.

Function deprecated Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.
Function knownfailureif Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.
Function parametrize Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.
Function setastest Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.
Function skipif Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.
Function slow Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.
Variable _needs_refcount Undocumented
def deprecated(conditional=True): (source)

Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.

Filter deprecation warnings while running the test suite.

This decorator can be used to filter DeprecationWarning's, to avoid printing them during the test suite run, while checking that the test actually raises a DeprecationWarning.

Notes

New in version 1.4.0.

Parameters
conditional:bool or callable, optionalFlag to determine whether to mark test as deprecated or not. If the condition is a callable, it is used at runtime to dynamically make the decision. Default is True.
Returns
functiondecorator - The deprecated decorator itself.
def knownfailureif(fail_condition, msg=None): (source)

Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.

Make function raise KnownFailureException exception if given condition is true.

If the condition is a callable, it is used at runtime to dynamically make the decision. This is useful for tests that may require costly imports, to delay the cost until the test suite is actually executed.

Notes

The decorator itself is decorated with the nose.tools.make_decorator function in order to transmit function name, and various other metadata.

Parameters
fail_condition:bool or callableFlag to determine whether to mark the decorated test as a known failure (if True) or not (if False).
msg:str, optionalMessage to give on raising a KnownFailureException exception. Default is None.
Returns
functiondecorator - Decorator, which, when applied to a function, causes KnownFailureException to be raised when fail_condition is True, and the function to be called normally otherwise.
def parametrize(vars, input): (source)

Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.

Pytest compatibility class. This implements the simplest level of pytest.mark.parametrize for use in nose as an aid in making the transition to pytest. It achieves that by adding a dummy var parameter and ignoring the doc_func parameter of the base class. It does not support variable substitution by name, nor does it support nesting or classes. See the pytest documentation for usage.

New in version 1.14.0.

def setastest(tf=True): (source)

Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.

Signals to nose that this function is or is not a test.

Notes

This decorator can't use the nose namespace, because it can be called from a non-test module. See also istest and nottest in nose.tools.

Examples

setastest can be used in the following way:

from numpy.testing import dec

@dec.setastest(False)
def func_with_test_in_name(arg1, arg2):
    pass

Parameters
tf:boolIf True, specifies that the decorated callable is a test. If False, specifies that the decorated callable is not a test. Default is True.
def skipif(skip_condition, msg=None): (source)

Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.

Make function raise SkipTest exception if a given condition is true.

If the condition is a callable, it is used at runtime to dynamically make the decision. This is useful for tests that may require costly imports, to delay the cost until the test suite is actually executed.

Notes

The decorator itself is decorated with the nose.tools.make_decorator function in order to transmit function name, and various other metadata.

Parameters
skip_condition:bool or callableFlag to determine whether to skip the decorated test.
msg:str, optionalMessage to give on raising a SkipTest exception. Default is None.
Returns
functiondecorator - Decorator which, when applied to a function, causes SkipTest to be raised when skip_condition is True, and the function to be called normally otherwise.
def slow(t): (source)

Deprecated since version 1.21: This decorator is retained for compatibility with the nose testing framework, which is being phased out. Please use the nose2 or pytest frameworks instead.

Label a test as 'slow'.

The exact definition of a slow test is obviously both subjective and hardware-dependent, but in general any individual test that requires more than a second or two should be labeled as slow (the whole suite consists of thousands of tests, so even a second is significant).

Examples

The numpy.testing module includes import decorators as dec. A test can be decorated as slow like this:

from numpy.testing import *

@dec.slow
def test_big(self):
    print('Big, slow test')

Parameters
t:callableThe test to label as slow.
Returns
callablet - The decorated test t.
_needs_refcount = (source)

Undocumented