Next topic

mmf.utils.examples

This Page

mmf.utils.decorators

slow(t) Labels a test as ‘slow’.
setastest([tf]) Signals to nose that this function is or is not a test
skipif(skip_condition[, msg]) Make function raise SkipTest exception if skip_condition is true
skipknownfailure(f) Decorator to raise SkipTest for test known to fail
with_args(*v, **kw) Decorator to define a functions argspec: ..

Decorators for labeling 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 metadata such as function name, setup and teardown functions and so on - see nose.tools for more information.

mmf.utils.decorators.slow(t)[source]

Labels 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 consits of thousands of tests, so even a second is significant).

mmf.utils.decorators.setastest(tf=True)[source]

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

Parameters :

tf : bool

If True specifies this is a test, not a test otherwise

Examples

::

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

...

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

mmf.utils.decorators.skipif(skip_condition, msg=None)[source]

Make function raise SkipTest exception if skip_condition is true

Parameters :

skip_condition : bool

Flag to determine whether to skip test (True) or not (False)

msg : string

Message to give on raising a SkipTest exception

Returns :

decorator : function

Decorator, which, when applied to a function, causes SkipTest to be raised when the skip_condition was True, and the function to be called normally otherwise.

Notes

You will see from the code that we had to further decorate the decorator with the nose.tools.make_decorator function in order to transmit function name, and various other metadata.

mmf.utils.decorators.skipknownfailure(f)[source]

Decorator to raise SkipTest for test known to fail

mmf.utils.decorators.with_args(*v, **kw)[source]

Decorator to define a functions argspec:

Examples

>>> def A(x,y): print "A(%r,%r)"%(x,y) 
>>> def B(y,z): print "A(%r,%r)"%(y,z) 
>>> @with_args(A,B)
... def C(t,args):
...     print "C(%r)"%(t)
...     with_args(A)(args)
...     with_args(B)(args)          
>>> C(x=1,y=2,z=3,t=4)              
C(4)
A(1,2)
B(2,3)