Skip to content

test: use match in pytest.raises#1846

Merged
bearomorphism merged 1 commit into
masterfrom
test-excinfo
May 12, 2026
Merged

test: use match in pytest.raises#1846
bearomorphism merged 1 commit into
masterfrom
test-excinfo

Conversation

@bearomorphism
Copy link
Copy Markdown
Collaborator

Description

Use match parameter in pytest.raises and remove verbose string assertions.

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Used cursor agent mode to assist this task.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (1090d66) to head (a9e7eb1).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1846   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files          61       61           
  Lines        2779     2779           
=======================================
  Hits         2730     2730           
  Misses         49       49           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

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

Updates the test suite to use pytest.raises(..., match=...) for asserting exception messages, reducing post-raises string assertions and making error-message checks more idiomatic.

Changes:

  • Replaced excinfo-based string assertions with pytest.raises(..., match=...) across multiple tests.
  • Added re.escape(...) in some places to safely match literal strings (e.g., filenames/paths) in regex-based match.
  • Minor cleanup in tests (e.g., removing unused captured stderr variable, using check=True in subprocess.run).

Reviewed changes

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

Show a summary per file
File Description
tests/test_git.py Uses match= for GitCommandError assertion.
tests/test_factory.py Uses match= for factory failure exception message.
tests/test_cz_customize.py Uses match= for missing customize config error message.
tests/test_conf.py Adds re and uses re.escape in match= for invalid config filename checks.
tests/test_cli.py Converts several raises assertions to match=, plus small cleanups.
tests/test_changelog.py Uses match= for changelog-related exceptions.
tests/test_bump_update_version_in_files.py Adds re and converts consistency error assertions to match=.
tests/commands/test_commit_command.py Adds re and converts several commit-command exception assertions to match=.
tests/commands/test_check_command.py Converts various check-command exception assertions to match= (including multi-message case).
tests/commands/test_changelog_command.py Uses match= for missing revision range case.
tests/commands/test_bump_command.py Converts bump-command exception assertions to match= in multiple scenarios.

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

Comment thread tests/test_bump_update_version_in_files.py
Comment thread tests/test_bump_update_version_in_files.py
Comment thread tests/test_factory.py
Comment thread tests/test_cz_customize.py
Comment thread tests/commands/test_bump_command.py Outdated
Comment thread tests/commands/test_bump_command.py Outdated
Comment thread tests/test_cli.py Outdated
Copy link
Copy Markdown
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

mostly good, a few nits from copilot

Comment thread tests/commands/test_bump_command.py Outdated
@bearomorphism
Copy link
Copy Markdown
Collaborator Author

Hi @Lee-W, addressed all the Copilot review comments and rebased onto latest master:

  • Used re.escape(...) for literal matches in test_factory.py, test_cz_customize.py, and the two test_bump_command.py cases that contain version numbers (per your "sound like a good idea" on the first one).
  • Extended the CurrentVersionNotFoundError regex in test_bump_update_version_in_files.py to also cover the follow-up version_files consistency hint.
  • Removed the unused capsys fixture from test_cz_config_file_without_correct_file_path.

Note on CI

The python-check (3.14, ubuntu-22.04) job is failing on an unrelated, pre-existing issue — Python 3.14.5 changed argparse's invalid-choice formatting (quoted vs unquoted choices), which broke the test_invalid_command[py_3.14-invalidCommand] file-regression fixture. Master's last green run was before the runner updated to 3.14.5. Filed #1990 for a separate fix.

All tests touched by this PR pass locally on Python 3.14.5; ruff + mypy are clean.

@bearomorphism
Copy link
Copy Markdown
Collaborator Author

Update on the unrelated 3.14 failure: confirmed it's Python 3.14.5 — released yesterday (2026-05-10) — landing CPython gh-130750:

Restore quoting of choices in argparse error messages for improved clarity and consistency with documentation.

So 3.14.0–3.14.4 emitted (choose from init, commit, ...) and 3.14.5 now emits (choose from 'init', 'commit', ...). Master's last green run on 2026-05-09 was still on 3.14.4. Tracked in #1990 — happy to take that one too once this PR lands.

@bearomorphism
Copy link
Copy Markdown
Collaborator Author

bearomorphism commented May 11, 2026

Filed #1991 (skip-on-3.14.5+) which should turn master CI green again — once that lands, a CI rerun on this PR should be green too. Note that #1991 is only the short-term skip; the longer-term normalization fix in #1990 remains open.

Comment thread tests/test_cli.py
@bearomorphism bearomorphism merged commit ce07c77 into master May 12, 2026
20 checks passed
@bearomorphism bearomorphism deleted the test-excinfo branch May 12, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants