gh-131178: Add tests for zipapp command-line interface#150203
Open
timurmamedov1 wants to merge 1 commit into
Open
gh-131178: Add tests for zipapp command-line interface#150203timurmamedov1 wants to merge 1 commit into
timurmamedov1 wants to merge 1 commit into
Conversation
9 tasks
There was a problem hiding this comment.
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
CommandLineTestclass that runspython -m zipappin 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 on lines
+468
to
+472
| def _run(self, *args): | ||
| return subprocess.run( | ||
| [sys.executable, '-m', 'zipapp', *args], | ||
| capture_output=True, | ||
| ) |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
CommandLineTestclass with subprocess-based tests forpython -m zipapp, covering:--help-o,-p,-m,-c)--info(with/without interpreter, nonexistent file)__main__.py)