Skip to content

Let scripted side_effect sequences absorb surplus mock calls#578

Merged
tobocop2 merged 1 commit into
mainfrom
fix/side-effect-list-exhaustion
Jul 21, 2026
Merged

Let scripted side_effect sequences absorb surplus mock calls#578
tobocop2 merged 1 commit into
mainfrom
fix/side-effect-list-exhaustion

Conversation

@tobocop2

Copy link
Copy Markdown
Owner

Problem

Eighteen tests script mocks with an exact-length side_effect=[...] list. The moment the mocked call happens once more than the author assumed, the list exhausts and raises StopIteration, which presents as an unrelated failure with no useful traceback. On a loaded CI host that extra call is exactly what happens: the Windows 3.12 lane has failed this way on a fully mocked test whose only upstream change was comment text.

Solution

Add a small shared helper, tests/_mock_effects.repeat_last, which chains the scripted effects into an endless repeat of the last one, and convert all 18 list-literal sites to it. A surplus call now returns the last scripted value and the test fails, if at all, on its own assertions with a readable diff. The two PropertyMock sites in the catalog tests script a get followed by a raising set, so they become a callable instead: any get reports the current tab and any set raises the way Textual's active validator does, however many times the code under test retries.

An exact-length side_effect=[...] list raises StopIteration the moment
the mocked call happens once more than the test scripted, which on a
loaded host presents as an unrelated failure with no useful traceback.
Add tests/_mock_effects.repeat_last, which chains the scripted effects
into an endless repeat of the last one, and convert the 18 list-literal
sites so a surplus call now trips the test's own assertions instead.

The two PropertyMock sites in the catalog tests script a get followed by
a raising set; those become a callable (any get reports the current tab,
any set raises like Textual's active validator) since tail-repeating
would make a surplus read raise the setter's error.
@tobocop2
tobocop2 merged commit dffdf09 into main Jul 21, 2026
6 of 17 checks passed
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.

1 participant