MCPcopy
hub / github.com/pytest-dev/pytest / tracemalloc_message

Function tracemalloc_message

src/_pytest/tracemalloc.py:4–24  ·  view source on GitHub ↗
(source: object)

Source from the content-addressed store, hash-verified

2
3
4def tracemalloc_message(source: object) -> str:
5 if source is None:
6 return ""
7
8 try:
9 import tracemalloc
10 except ImportError:
11 return ""
12
13 tb = tracemalloc.get_object_traceback(source)
14 if tb is not None:
15 formatted_tb = "\n".join(tb.format())
16 # Use a leading new line to better separate the (large) output
17 # from the traceback to the previous warning text.
18 return f"\nObject allocated at:\n{formatted_tb}"
19 # No need for a leading new line.
20 url = "https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings"
21 return (
22 "Enable tracemalloc to get traceback where the object was allocated.\n"
23 f"See {url} for more info."
24 )

Callers 3

unraisable_hookFunction · 0.90
thread_exception_hookFunction · 0.90
warning_record_to_strFunction · 0.90

Calls 2

joinMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…