def timedtest(max_time, tolerance=TOLERANCE):
 def _timedtest(function):
  def wrapper(*args, **kw):
   start_time = time.time()
   try:
    function(*args, **kw)
   finally:
    total_time = (time.time() - start_time)
    if (total_time > (max_time + tolerance)):
     raise DurationError(('Test was too long (%.2f s)' % total_time))
  return wrapper
 return _timedtest

def timedtest ( max_time , tolerance = TOLERANCE ) : def _timedtest ( function ) : def wrapper ( * args , ** kw ) : start_time = time . time ( ) try : function ( * args , ** kw ) finally : total_time = ( time . time ( ) - start_time ) if ( total_time > ( max_time + tolerance ) ) : raise DurationError ( ( 'Test was too long (%.2f s)' % total_time ) ) return wrapper return _timedtest
timedtest decorator decorates the test method with a timer when the time spent by the test exceeds max_time in seconds .