Esempio n. 1
0
 def __stoppable_test_function(self, data):
     """Run ``self._test_function``, but convert a ``StopTest`` exception
     into a normal return and avoid raising Flaky for RecursionErrors.
     """
     depth = stack_depth_of_caller()
     # Because we add to the recursion limit, to be good citizens we also add
     # a check for unbounded recursion.  The default limit is 1000, so this can
     # only ever trigger if something really strange is happening and it's hard
     # to imagine an intentionally-deeply-recursive use of this code.
     assert depth <= 1000, (
         "Hypothesis would usually add %d to the stack depth of %d here, "
         "but we are already much deeper than expected.  Aborting now, to "
         "avoid extending the stack limit in an infinite loop..." %
         (self.__recursion_limit, depth))
     try:
         sys.setrecursionlimit(depth + self.__recursion_limit)
         self._test_function(data)
     except StopTest as e:
         if e.testcounter == data.testcounter:
             # This StopTest has successfully stopped its test, and can now
             # be discarded.
             pass
         else:
             # This StopTest was raised by a different ConjectureData. We
             # need to re-raise it so that it will eventually reach the
             # correct engine.
             raise
     finally:
         sys.setrecursionlimit(self.__recursion_limit)
Esempio n. 2
0
def recur(i):
    assert len(inspect.stack(0)) == stack_depth_of_caller()
    if i >= 1:
        recur(i - 1)