GeezerVison is showing github.com — gh-131178: Add tests for `pstats` command-line interface by iamsharduld · Pull Request #157133 · python/cpython
Conversation
iamsharduld
commented
Sep 7, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Adds tests for the interactive profile browser started by python -m pstats, which had none (test_pstats.py only covered the Stats API).
The browser only exists inside the module's __main__ block, so the tests run it in a subprocess with script_helper.spawn_python() and feed commands on stdin. A small profile is generated once per class with cProfile from two module-level functions, one of which calls the other three times, so the expected call counts, callers and callees are known.
Covered:
- Startup banner, prompt,
quit, and EOF on stdin.
- A profile given on the command line, several profiles (added together), and a missing one.
read (with an argument, without one to reload, missing file, non-marshal file) and add (including a missing file).
stats with an integer, a fraction, a regular expression, and an out-of-range fraction.
sort by a full key and by a unique prefix, sort with no or an invalid key, reverse, strip.
callers and callees.
help and help stats.
- Every command's behaviour when no statistics are loaded.
Assertions avoid anything timing-dependent: they check call counts, the relative order of the two known functions, and the exact messages printed by the browser. The class is guarded with support.requires_subprocess(). The 20 new tests take about 1.2 s on a debug build here.
Ran test_pstats repeatedly, make patchcheck and the pre-commit hooks on macOS.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The interactive profile browser started by ``python -m pstats`` had no
tests. Drive it through a subprocess and check each documented command,
the prompts, the report header, sorting, restrictions, callers and
callees, help, and the error paths.
iamsharduld
commented
Sep 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Dropped the NEWS entry: this changes only tests, which the devguide lists among the exemptions. The same point was made on #157171 ("This is a fix to unreleased test. It does not need a NEWS entry") and on #157158, so I am applying it across my open test-only PRs rather than having it raised on each one. bedevere/news will stay red until skip news is applied.
(Edited to remove two user mentions that pinged core developers for no reason. Sorry for the noise.)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
You should not ping core devs unnecessarily.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
You are right, sorry. I mentioned two core developers by name across three PRs to explain where the convention came from, which pinged you both for nothing. I have edited those comments to reference the PR numbers instead, and I will link to the discussion rather than name people from now on.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|