Skip to content

feat(pytest-plugin): easier assertions on error contents - #499

Merged
lengau merged 3 commits into
mainfrom
work/pytest-error-assertion
Oct 9, 2026
Merged

lengau merged 3 commits into
mainfrom
work/pytest-error-assertion

Conversation

@bepri

@bepri bepri commented Oct 9, 2026 •

Copy link
Copy Markdown
Member
  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run make lint && make test?

Adds a new function to the pytest plugin to make testing CraftErrors easier. Now, instead of this:

with pytest.raises(CraftError, match="the message field") as raised:
  fallible()

assert raised.details == "some details"
assert raised.retcode == 2

you can just do:

with raises_craft_error(CraftError, match="the message field", details="some details", retcode=2):
  fallible()

This should be a drop-in replacement for any block that already uses pytest.raises().


Stack created with GitHub Stacks CLI • Give Feedback 💬

@bepri
bepri requested a review from a team as a code owner October 9, 2026 15:28
@bepri
bepri added this pull request to stack #500 October 9, 2026 15:28
@lengau
lengau requested a review from a team October 9, 2026 15:40
Comment thread craft_cli/pytest_plugin.py
Copilot AI lite review requested due to automatic review settings October 9, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Regenerate and commit uv.lock so frozen documentation builds remain valid.

1 open finding
What changed in this PR

Adds raises_craft_error to simplify assertions on CraftError contents.

Changes:

  • Implements the new pytest helper.
  • Adds comprehensive tests.
  • Updates pytest requirements and changelog documentation.
File Summary
tests/​test_pytest_plugin.py Tests helper matching and failure behavior.
pyproject.toml Updates the pytest requirement.
docs/​changelog.rst Documents the new feature.
craft_cli/​pytest_plugin.py Implements the assertion helper.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pyproject.toml
@lengau
lengau requested a review from a team October 9, 2026 15:47
Base automatically changed from work/pytest-plugin-group to main October 9, 2026 16:04
@lengau
lengau force-pushed the work/pytest-error-assertion branch from 0cb3c64 to 413607e Compare October 9, 2026 16:04
@lengau
lengau merged commit 19c2772 into main Oct 9, 2026
31 checks passed
@lengau
lengau deleted the work/pytest-error-assertion branch October 9, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants