gh-131178: Add tests for `ensurepip` command-line interface by iamsharduld · Pull Request #157154 · python/cpython · GitHub
Skip to content

gh-131178: Add tests for ensurepip command-line interface - #157154

Open
iamsharduld wants to merge 2 commits into
python:mainfrom
iamsharduld:gh-131178-ensurepip-cli-tests
Open

gh-131178: Add tests for ensurepip command-line interface#157154
iamsharduld wants to merge 2 commits into
python:mainfrom
iamsharduld:gh-131178-ensurepip-cli-tests

Conversation

@iamsharduld

@iamsharduld iamsharduld commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The documented command-line interface of ensurepip has six options, but test_ensurepip.py only called _main() with --version and with no arguments. The options themselves were covered only through bootstrap(), so a mistake in the argument parser or in how _main() forwards the parsed options would not have been caught.

This adds tests to the existing TestBootstrappingMainFunction class, one per documented option, in the same style as the TestBootstrap tests (pip is mocked, the arguments passed to pip and ENSUREPIP_OPTIONS are asserted):

  • --root, --user, --upgrade and -U, -v / --verbose / -vv / repeated -v
  • --altinstall, --default-pip, and the documented exception when both are given
  • all options together, checking the order of the options does not matter
  • --help lists every documented option and does not run pip
  • an unknown option exits with status 2 and does not run pip

Tests-only; a NEWS entry is included in the Tests section like the earlier PRs in this series that shipped one.

Ran test_ensurepip (also with -R 3:3), make patchcheck and the pre-commit hooks on macOS.

The documented options of ``python -m ensurepip`` (--upgrade, --user,
--root, --altinstall, --default-pip, --verbose) were only tested through
bootstrap(), not through the command line. Drive each one through
_main() with pip mocked, including the altinstall/default-pip conflict,
--help and an unknown option.
@bedevere-app bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels Sep 8, 2026
@iamsharduld

Copy link
Copy Markdown
Contributor Author

@iamsharduld

iamsharduld commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

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