def timed(limit):
def decorate(func):<EOL><INDENT>def newfunc(*arg, **kw):<EOL><INDENT>start = time.time()<EOL>func(*arg, **kw)<EOL>end = time.time()<EOL>if end - start > limit:<EOL><INDENT>raise TimeExpired("<STR_LIT>" % limit)<EOL><DEDENT><DEDENT>newfunc = make_decorator(func)(newfunc)<EOL>return newfunc<EOL><DEDENT>return decorate<EOL>
Test must finish within specified time limit to pass.

    Example use::

      @timed(.1)
      def test_that_fails():
          time.sleep(.2)