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