MCPcopy Index your code
hub / github.com/python/cpython / capture_test_stack

Function capture_test_stack

Lib/test/test_asyncio/test_graph.py:11–45  ·  view source on GitHub ↗
(*, fut=None, depth=1)

Source from the content-addressed store, hash-verified

9
10
11def capture_test_stack(*, fut=None, depth=1):
12
13 def walk(s):
14 ret = [
15 (f"T<{n}>" if '-' not in (n := s.future.get_name()) else 'T<anon>')
16 if isinstance(s.future, asyncio.Task) else 'F'
17 ]
18
19 ret.append(
20 [
21 (
22 f"s {entry.frame.f_code.co_name}"
23 if entry.frame.f_generator is None else
24 (
25 f"a {entry.frame.f_generator.cr_code.co_name}"
26 if hasattr(entry.frame.f_generator, 'cr_code') else
27 f"ag {entry.frame.f_generator.ag_code.co_name}"
28 )
29 ) for entry in s.call_stack
30 ]
31 )
32
33 ret.append(
34 sorted([
35 walk(ab) for ab in s.awaited_by
36 ], key=lambda entry: entry[0])
37 )
38
39 return ret
40
41 buf = io.StringIO()
42 asyncio.print_call_graph(fut, file=buf, depth=depth+1)
43
44 stack = asyncio.capture_call_graph(fut, depth=depth)
45 return walk(stack), buf.getvalue()
46
47
48class CallStackTestBase:

Callers 5

c5Method · 0.85
gen_nested_callMethod · 0.85
deepMethod · 0.85
innerMethod · 0.85
mainMethod · 0.85

Calls 2

getvalueMethod · 0.95
walkFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…