fix(pytest_plugin): reject negative advance in _RecordingProgresser - #467
Open
GreyViperTooth wants to merge 2 commits into
Open
Conversation
The `emitter` fixture swaps the real progress bar for `_RecordingProgresser`, but that mock did not enforce a constraint the real `_Progresser.advance` does: it raises `ValueError` when `amount < 0`. As a result, tests using the fixture silently accepted negative advances that crash in production, masking real bugs (see canonical/craft-application#994). Give the mock the same single-positional `amount` signature and the same negative-amount guard as the real method. The recorded-call format is unchanged (`call("advance", 100)`), so existing assertions still hold. Fixes canonical#466 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
GreyViperTooth
force-pushed
the
fix/issue-466-recording-progresser-negative-advance
branch
from
August 3, 2026 02:09
9ffba1c to
42d5f89
Compare
bepri
reviewed
Aug 3, 2026
bepri
left a comment
Member
There was a problem hiding this comment.
Thanks! I left a little feedback below. Could you also add this as a bugfix in the changelog at docs/changelog.rst?
Comment on lines
+243
to
+245
|
|
||
| Mirrors the validation done by the real ``_Progresser.advance`` so that | ||
| tests using the ``emitter`` fixture don't silently accept invalid usage. |
Member
There was a problem hiding this comment.
We can skip this addition to the docstring, I think.
| def advance(self, *a: Any, **k: Any) -> None: | ||
| """Record the advance usage.""" | ||
| self.recording_emitter.record("advance", a, k) | ||
| def advance(self, amount: float) -> None: |
Member
There was a problem hiding this comment.
This breaks the API of this fixture, I would do this instead:
Suggested change
| def advance(self, amount: float) -> None: | |
| def advance(self, *a: Any, amount: float, **k: Any) -> None: |
(and update line 249 accordingly)
- Restore the generic *a/**k passthrough on _RecordingProgresser.advance (with amount first so positional calls keep working) instead of narrowing the signature, and drop the docstring expansion. - Add a bugfix entry to docs/changelog.rst. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Thanks @bepri! Kept the *a/**k passthrough and dropped the docstring as suggested. One tweak: I put amount first (def advance(self, amount, *a, **k)) instead of keyword-only, since *a, amount, **k would break the existing positional call progress_bar.advance(100). Also added the changelog entry. |
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.
What
The
emitterpytest fixture swaps the real progress bar for_RecordingProgresser, but that mock did not enforce a constraint the real_Progresser.advancedoes: it raisesValueErrorwhenamount < 0. As a result, tests using the fixture silently accepted negative advances that would crash in production, which can mask real bugs (this was noticed in canonical/craft-application#994).How
_RecordingProgresser.advancethe same single-positionalamount: floatsignature as the real_Progresser.advance.raise ValueErroronamount < 0).call(advance, 100)), so existing fixture assertions still hold.Fixes #466
🤖 Generated with Claude Code