gh-131178: Add tests for pstats command-line interface - #157133
gh-131178: Add tests for pstats command-line interface#157133iamsharduld wants to merge 3 commits into
pstats command-line interface#157133Conversation
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.
|
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 (Edited to remove two user mentions that pinged core developers for no reason. Sorry for the noise.) |
|
You should not ping core devs unnecessarily. |
|
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. |
Adds tests for the interactive profile browser started by
python -m pstats, which had none (test_pstats.pyonly covered theStatsAPI).The browser only exists inside the module's
__main__block, so the tests run it in a subprocess withscript_helper.spawn_python()and feed commands on stdin. A small profile is generated once per class withcProfilefrom two module-level functions, one of which calls the other three times, so the expected call counts, callers and callees are known.Covered:
quit, and EOF on stdin.read(with an argument, without one to reload, missing file, non-marshal file) andadd(including a missing file).statswith an integer, a fraction, a regular expression, and an out-of-range fraction.sortby a full key and by a unique prefix,sortwith no or an invalid key,reverse,strip.callersandcallees.helpandhelp stats.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_pstatsrepeatedly,make patchcheckand the pre-commit hooks on macOS.