FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131178: Add tests for `pstats` command-line interface by iamsharduld · Pull Request #157133 · python/cpython · GitHub

Repository navigation

gh-131178: Add tests for pstats command-line interface - #157133

Open
iamsharduld wants to merge 3 commits into
python:mainfrom
iamsharduld:gh-131178-pstats-cli-tests
Open

iamsharduld wants to merge 3 commits into
python:mainfrom
iamsharduld:gh-131178-pstats-cli-tests

Conversation

iamsharduld commented Sep 7, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

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.

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.
bedevere-app Bot mentioned this pull request Sep 7, 2026
7 of 9 tasks
bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels Sep 7, 2026

iamsharduld commented Sep 9, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

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.)

Copy link
Copy Markdown
Contributor

You should not ping core devs unnecessarily.

Copy link
Copy Markdown
Contributor Author

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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL