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 |
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.
deprecated
decorator itself.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.
fail_condition
is True,
and the function to be called normally otherwise.The decorator itself is decorated with the nose.tools.make_decorator function in order to transmit function name, and various other metadata.
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.
Signals to nose that this function is or is not a test.
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.
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
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.
skip_condition
is True, and the function
to be called normally otherwise.The decorator itself is decorated with the nose.tools.make_decorator function in order to transmit function name, and various other metadata.
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).
t
.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')