Let scripted side_effect sequences absorb surplus mock calls#578
Merged
Conversation
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.
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.
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.