pytest-memray API

Types

class pytest_memray.LeaksFilterFunction

Bases: Protocol

A callable that can decide whether to ignore some memory leaks.

This can be used to suppress leak reports from locations that are known to leak. For instance, you might know that objects of a certain type are cached by the code you’re invoking, and so you might want to ignore all reports of leaked memory allocated below that type’s constructor.

You can provide any callable with the following signature as the filter_fn keyword argument for the limit_leaks marker:

__call__(stack: Stack) bool

Return whether allocations from this stack should be reported.

Return True if you want the leak to be reported, or False if you want it to be suppressed.

class pytest_memray.Stack

The call stack that led to some memory allocation.

You can inspect the frames which make up the call stack.

frames: Tuple[StackFrame, ...]

The frames that make up the call stack, most recent first.

class pytest_memray.StackFrame

One frame of a call stack.

Each frame has attributes to tell you what code was executing.

filename: str

The source file being executed, or "???" if unknown.

function: str

The function being executed, or "???" if unknown.

lineno: int

The line number of the executing line, or 0 if unknown.