Skip to content

gh-131178: Add tests for cProfile command-line interface - #144918

Open
NekoAsakura wants to merge 2 commits into
python:mainfrom
NekoAsakura:gh-131178-cprofile-cli-tests
Open

gh-131178: Add tests for cProfile command-line interface#144918
NekoAsakura wants to merge 2 commits into
python:mainfrom
NekoAsakura:gh-131178-cprofile-cli-tests

Conversation

@NekoAsakura

@NekoAsakuraNekoAsakura commented Feb 17, 2026

Copy link
Copy Markdown
Member

The existing TestCommandLine class only had two tests (invalid sort option and main namespace). This expands coverage to exercise all major CLI code paths:

  • help output (-h/--help)

  • no arguments (usage + exit code 2)

  • unknown option (error + exit code 2)

  • invalid sort option (error + exit code 2)

  • valid sort options with both -s and --sort forms

  • output file with both -o and --outfile forms

  • profiling a script file

  • profiling a module via -m

  • nonexistent script file (FileNotFoundError)

    New tests added

    TestCode path
    test_help-h/--help prints usage with correct program name
    test_no_argsNo arguments prints usage and exits with code 2
    test_unknown_optionUnknown flag gives error and exits with code 2
    test_invalid_sortInvalid -s value gives optparse error (strengthened from assertGreater(rc, 0) to assertEqual(rc, 2))
    test_valid_sortValid sort keys with both -s and --sort
    test_outfile-o/--outfile writes non-empty profile data
    test_profile_scriptProfiling a script produces stats output
    test_profile_module-m flag profiles a library module
    test_nonexistent_scriptMissing script gives FileNotFoundError

The existing TestCommandLine class only had two tests (invalid sort
option and __main__ namespace). This expands coverage to exercise
all major CLI code paths:
- help output (-h/--help)
- no arguments (usage + exit code 2)
- unknown option (error + exit code 2)
- invalid sort option (error + exit code 2)
- valid sort options with both -s and --sort forms
- output file with both -o and --outfile forms
- profiling a script file
- profiling a module via -m
- nonexistent script file (FileNotFoundError)
@bedevere-appbedevere-appBot added awaiting review tests Tests in the Lib/test dir labels Feb 17, 2026
@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label May 6, 2026
@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label May 17, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewtestsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@NekoAsakura