Skip to content

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

Open
NekoAsakura wants to merge 1 commit intopython:mainfrom
NekoAsakura:gh-131178-cprofile-cli-tests
Open

gh-131178: Add tests for cProfile command-line interface#144918
NekoAsakura wants to merge 1 commit intopython:mainfrom
NekoAsakura:gh-131178-cprofile-cli-tests

Conversation

@NekoAsakura
Copy link

@NekoAsakura NekoAsakura commented Feb 17, 2026

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

    Test Code path
    test_help -h/--help prints usage with correct program name
    test_no_args No arguments prints usage and exits with code 2
    test_unknown_option Unknown flag gives error and exits with code 2
    test_invalid_sort Invalid -s value gives optparse error (strengthened from assertGreater(rc, 0) to assertEqual(rc, 2))
    test_valid_sort Valid sort keys with both -s and --sort
    test_outfile -o/--outfile writes non-empty profile data
    test_profile_script Profiling a script produces stats output
    test_profile_module -m flag profiles a library module
    test_nonexistent_script Missing 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-app bedevere-app bot added awaiting review tests Tests in the Lib/test dir labels Feb 17, 2026
@bedevere-app
Copy link

bedevere-app bot commented Feb 17, 2026

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.

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.

1 participant