test(cli): skip invalid-command snapshot on Python 3.12.0-3.12.6#1982
Open
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Open
test(cli): skip invalid-command snapshot on Python 3.12.0-3.12.6#1982bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Conversation
Closes commitizen-tools#1864. The reference snapshots for `test_invalid_command` reflect the no-quote argparse error format that landed in CPython 3.13 and was backported to 3.12.7 (gh-129019). On Python 3.12.0-3.12.6 argparse still prints quoted choices, so the snapshot diff fails for those patch releases. Skip the test on 3.12.0-3.12.6 with a precise `skipif` rather than maintaining a duplicate snapshot. The CI matrix already runs on recent 3.12.x where the test is exercised; users on older patches just see the test as `s` instead of a hard failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1982 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 61 61
Lines 2779 2779
=======================================
Hits 2730 2730
Misses 49 49 ☔ View full report in Codecov by Sentry. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the CLI snapshot test suite to account for an argparse error-message formatting difference present in Python 3.12.0–3.12.6, where choices are rendered with quotes, conflicting with the existing reference snapshots (which match the 3.12.7+/3.13+ “no-quote” format).
Changes:
- Skip
test_invalid_commandon Python 3.12.0–3.12.6 using a precisepytest.mark.skipifpatch-version check. - Add an explanatory skip reason referencing the upstream
argparsebehavior change and the related issue.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 9, 2026
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.
Description
Closes #1864.
Why
tests/test_cli.py::test_invalid_commandis a snapshot test that captures the stderr output ofcz <invalid>. The output is generated by argparse, and CPython 3.13 changed the format of theinvalid choice:error from quoted choices ('init', 'commit', ...) to unquoted (init, commit, ...) — see CPython gh-129019. The change was backported to 3.12.7. The repo's reference snapshots reflect the no-quote format, so:A user on 3.12.3 hits
AssertionError: FILES DIFFERrunningpytest tests/test_cli.py::test_invalid_command. The CI matrix runs on a recent 3.12.x, so CI doesn't catch it.What changed
tests/test_cli.pypytest.mark.skipif(sys.version_info[:2] == (3, 12) and sys.version_info < (3, 12, 7), reason=...)to thetest_invalid_commandparametrised test. The reason text references CPython gh-129019 and this issue.How it works
sys.version_info[:2] == (3, 12)scopes the skip to Python 3.12.x only — older 3.10/3.11 (which still print quoted choices) and newer 3.13/3.14 (which print unquoted) are unaffected.sys.version_info < (3, 12, 7)uses Python's lexicographic tuple comparison:(3, 12, 6, ...) < (3, 12, 7)isTrue,(3, 12, 7, ...) < (3, 12, 7)isFalse. So 3.12.0 through 3.12.6 skip; 3.12.7+ run.--invalid-argparametrised case shares the same decorator. Its argparse path also formats choices, so the same skip logic applies even though the diff message is slightly different.Why a
skipifinstead of duplicate snapshots?A
skipifis cheaper to maintain (no new fixture file, no risk of the duplicate snapshot drifting). It's also more honest: argparse's behaviour on 3.12.0-3.12.6 is a known upstream issue, fixed in 3.12.7. Users on those patches can upgrade; we don't need commitizen to keep accumulating fixtures for upstream's old behaviour.Backward compatibility
czusers.test_invalid_commandon every supported Python because the GitHub-hosted runners use a recent patch within each minor (3.12.10+ at the time of writing).Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Claude following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and tests (poe lintclean; verified the test runs on a recent 3.12.x and skips on an old one — see "Steps to Test")Expected Behavior
pytest tests/test_cli.py -k test_invalid_commandgh-129019rationaleSteps to Test This Pull Request
Additional Context
Surfaced while triaging open issues in #1976 (round 3). The original reporter and
@noirbizarre(the assignee) had already discussed skipping the test on 3.12 — this PR scopes that skip to the affected patch range so the test still runs on every patch where the snapshot is valid. Reviewed by an internalclaude-sonnet-4.6code-review pass and by GitHub Copilot; both confirmed the version-tuple comparison and that the 3.10/3.11 snapshots are safe (security-only maintenance precludes the same back-port there).