Skip to content

Reduce verbosity of @limit_memory failure output - #171

Merged
godlygeek merged 1 commit into
bloomberg:mainfrom
blingblin-g:feat/verbosity-memray
Jul 1, 2026
Merged

Reduce verbosity of @limit_memory failure output#171
godlygeek merged 1 commit into
bloomberg:mainfrom
blingblin-g:feat/verbosity-memray

Conversation

@blingblin-g

@blingblin-g blingblin-g commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Closes #142.

Context — PyCon US sprint

Prototyped at the PyCon US sprint. The first draft rolled its own ini lookup, but a maintainer pointed me at pytest's standard helper for this case: Config.get_verbosity(verbosity_type). The current implementation defers to that.

Why the fallback

Config.get_verbosity only exists in pytest 8.0+. This package still declares pytest>=7.2, so I kept a small try/except AttributeError block that mirrors the helper's behavior on older pytest. Happy to drop it and bump pytest>=8.0 instead — say the word and I'll squash.

@blingblin-g
blingblin-g force-pushed the feat/verbosity-memray branch from 41e6b0c to 9655253 Compare June 5, 2026 02:32
@blingblin-g
blingblin-g marked this pull request as draft June 5, 2026 02:34
@blingblin-g
blingblin-g force-pushed the feat/verbosity-memray branch from 9655253 to 93adbd8 Compare June 5, 2026 04:11
@blingblin-g
blingblin-g force-pushed the feat/verbosity-memray branch from 93adbd8 to 9661579 Compare June 29, 2026 09:12
@godlygeek
godlygeek marked this pull request as ready for review June 30, 2026 22:19
@godlygeek
godlygeek force-pushed the feat/verbosity-memray branch 3 times, most recently from 75d0033 to b454962 Compare June 30, 2026 22:31
@godlygeek
godlygeek requested a review from sarahmonod June 30, 2026 22:33
godlygeek
godlygeek previously approved these changes Jun 30, 2026

@godlygeek godlygeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM after the updates I've made, but @sarahmonod would you mind giving it a look as well since I made quite a few changes?

@sarahmonod sarahmonod left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Add a `verbosity_memray` pytest option that controls whether the
per-allocation list is shown when the `limit_memory` marker fails.

By default the long "List of allocations:" section now shows only the
top 10 allocations by size for each failures. With `-q` or a negative
verbosity setting, only the one-line summary is displayed ("Test was
limited to X but allocated Y"). With `-vv` or a verbosity setting of
2 or more, all allocations are shown, the old default.

Drop support for pytest 7.x, which was superseded around 2.5 years ago
and which doesn't provide the `Config.get_verbosity` API we need.

Signed-off-by: Soojin Yoon <luvbliny@gmail.com>
Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
@godlygeek
godlygeek force-pushed the feat/verbosity-memray branch from 9287c1c to 84403df Compare July 1, 2026 19:28
@godlygeek

Copy link
Copy Markdown
Contributor

Thanks for the contribution, @blingblin-g!

@godlygeek

Copy link
Copy Markdown
Contributor

I think I somehow missed posting a comment explaining what changes I decided to make here, so for posterity: I updated this PR to drop support for pytest 7.x (which is now >2.5 years out of date). pytest 8.x supports every Python version that pytest-memray does, so this didn't require dropping support for any old Python versions.

I also switched it to have 3 tiers instead of just 2: by default, it shows the top 10 allocations by size, with -vv or a verbosity of 2 it shows all of them (the old default), and with -q or a negative verbosity it omits the list of allocations entirely (what @blingblin-g's original implementation of this PR did for the default verbosity level).

I'm hoping that gives people a bit more info by default without overwhelming them.

@godlygeek
godlygeek merged commit 902b21e into bloomberg:main Jul 1, 2026
13 checks passed
@blingblin-g

Copy link
Copy Markdown
Contributor Author

Wow, the 3-tier verbosity makes perfect sense! Thanks for polishing my initial PR and merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce verbosity of @pytest.mark.limit_memory on failure

3 participants