@pytest.fixture
def deep_stats(depth=sys.getrecursionlimit(), skip_if_no_recursion_error=True):
    # Define a function with deep recursion.
    def x0(frames):
        frames.append(sys._getframe())
    locals_ = locals()
    for x in range(1, depth):
        code = dedent('''
        import sys
        def x%d(frames):
            frames.append(sys._getframe())
            x%d(frames)
        ''' % (x, x - 1))
        exec_(code, locals_)
    f = locals_['x%d' % (depth - 1)]
    frames = []
    try:
        f(frames)
    except __HOLE__:
        # Expected.
        pass
    else:
        # Maybe PyPy.
        if skip_if_no_recursion_error:
            pytest.skip('Recursion limit not exceeded')
    # Profile the deepest frame.
    profiler = TracingProfiler()
    profiler._profile(frames[-1], 'call', None)
    spin(0.5)
    profiler._profile(frames[-1], 'return', None)
    # Test with the result.
    stats, __, __ = profiler.result()
    return stats
dataset/ETHPy150Open what-studio/profiling/test/test_stats.py/deep_stats