Skip to content

gh-131178: Add tests for zipapp command-line interface#150203

Open
timurmamedov1 wants to merge 1 commit into
python:mainfrom
timurmamedov1:gh-131178-zipapp-cli-tests
Open

gh-131178: Add tests for zipapp command-line interface#150203
timurmamedov1 wants to merge 1 commit into
python:mainfrom
timurmamedov1:gh-131178-zipapp-cli-tests

Conversation

@timurmamedov1
Copy link
Copy Markdown

@timurmamedov1 timurmamedov1 commented May 21, 2026

Add CommandLineTest class with subprocess-based tests for python -m zipapp, covering:

  • --help
  • Archive creation (-o, -p, -m, -c)
  • --info (with/without interpreter, nonexistent file)
  • Archive copying
  • Error cases (in-place copy, changing main on copy, missing source, no __main__.py)

Copilot AI review requested due to automatic review settings May 21, 2026 22:19
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented May 21, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends CPython’s zipapp test suite by adding a new subprocess-driven test class that exercises the real python -m zipapp command-line interface, complementing the existing in-process zipapp.main() CLI tests.

Changes:

  • Add a CommandLineTest class that runs python -m zipapp in a subprocess and validates key CLI behaviors (--help, create/copy archives, --info, and common error cases).
  • Add a NEWS entry documenting the new subprocess-based CLI coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Lib/test/test_zipapp.py Adds subprocess-based CLI tests for python -m zipapp and related helpers.
Misc/NEWS.d/next/Tests/2026-05-21-22-06-07.gh-issue-131178.zipapp_cli.rst Notes the addition of subprocess-based zipapp CLI tests.
Comments suppressed due to low confidence (2)

Lib/test/test_zipapp.py:561

  • This test currently treats any non-zero exit as success. To avoid false positives, also assert that stderr includes the specific message for in-place archive edits ("In-place editing of archives is not supported").
    def test_copy_archive_inplace_fails(self):
        original = self._make_archive()
        result = self._run(str(original), '-o', str(original))
        self.assertNotEqual(result.returncode, 0)

Lib/test/test_zipapp.py:567

  • Similar to the other negative tests, this only asserts a non-zero return code. To prevent the test passing for an unrelated failure mode, also check stderr contains the expected message for attempting to change the main function when copying ("Cannot change the main function when copying").
    def test_copy_archive_change_main_fails(self):
        original = self._make_archive()
        target = self.tmpdir / 'copy.pyz'
        result = self._run(str(original), '-o', str(target), '-m', 'foo:bar')
        self.assertNotEqual(result.returncode, 0)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Lib/test/test_zipapp.py
Comment on lines +468 to +472
def _run(self, *args):
return subprocess.run(
[sys.executable, '-m', 'zipapp', *args],
capture_output=True,
)
Comment thread Lib/test/test_zipapp.py
Comment on lines +546 to +549
def test_info_nonexistent_file(self):
target = self.tmpdir / 'nonexistent.pyz'
result = self._run(str(target), '--info')
self.assertNotEqual(result.returncode, 0)
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