bloomberg / bloomberg/pytest-memray

Allow non-aggregated memray captures

Open
#160 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
423
Forks
39
Avg merge
5h 19m
Merged PRs (30d)
1

Description

# Feature Request

## Is Your Feature Request Related to a Problem? Please Describe.

Currently, `pytest-memray` generates aggregated capture `.bin` files by default [#107](https://github.com/bloomberg/pytest-memray/issues/107) [Release 1.6.0](https://github.com/bloomberg/pytest-memray/releases/tag/1.6.0).
While this is efficient for disk usage, aggregated captures cannot be used with several memray features (e.g. `memray stats` or other reporters that require per-allocation data). Attempting to use these features results in errors such as:

```
NotImplementedError: Can't compute statistics using a pre-aggregated capture file.
```

This makes it impossible to use `pytest-memray` for workflows that rely on detailed allocation statistics.

## Describe the Solution You'd like

Add a configurable option to allow users to disable aggregation and output a full (non-aggregated) memray capture file, equivalent to running `memray run` without `--aggregate`.

Possible interfaces:

- A pytest CLI flag (e.g. `--memray-no-aggregate` or `--memray-full`)
- A pytest.ini / pyproject.toml option
- An environment variable for CI use

Default behavior could remain unchanged (aggregated captures), preserving current performance characteristics.

**Drawbacks:**

- Full capture files are larger and may increase disk usage and runtime overhead.
- Users should explicitly opt in and understand the trade-off.

## Describe Alternatives You've Considered

Use old `pytest-memray` release (< 1.6.0)

## Teachability, Documentation, Adoption, Migration Strategy

- Documentation can explain the difference between aggregated and full capture modes, including which memray reporters require full allocation data.
- Examples can show how to enable full capture mode when `memray stats` or similar tools are needed.
- No migration impact: existing users see no behavior change unless they opt in.
- This option would make `pytest-memray` more flexible and suitable for advanced memory analysis workflows.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the pytest CLI and configuration entry points that control capture generation, then check how the current integration invokes `memray run` and aggregation. Define an opt-in path that preserves the existing default and verify that the resulting capture works with `memray stats`; update documentation and tests for both modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.