Repository navigation
Preserve iterator matchers for every request - #848
Open
anticipate218 wants to merge 2 commits into
Open
anticipate218 wants to merge 2 commits into
anticipate218 wants to merge 2 commits into
Conversation
Snapshot the documented matcher iterable when constructing a response so every attempt checks the same callbacks. Cover generator reuse after success and failure and repeated response registration. Assisted-by: OpenAI Codex
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 type of PR is this? (check all applicable)
Description
The documented
matchiterable can be a generator or iterator. Currently, matching consumes it, so later requests can bypass callbacks that were already consumed. For example, after one request with the required header succeeds, subsequent requests with a wrong header also receive the mocked response. An earlier failed attempt can similarly leave only part of the callback chain.Materialize the iterable as a tuple when the response is created, as the existing URL-query path already does. All attempts then run the same callback collection. This also lets a response built with generator matchers be registered twice through the registry's existing deep-copy path. The original iterable is consumed at construction; later changes to an input list do not change the response's callbacks. The callback objects themselves are retained.
Related Issues
No existing issue identified for this matcher-collection lifecycle bug. The iterator request-body change in #840 concerns request content and is a different path.
PR checklist
Before submitting this pull request, I have done the following:
toxandpre-commitchecks locally: their wrappers and full interpreter matrix were not run; direct checks are listed below.Added/updated tests?
Validation on Windows / CPython 3.13.5:
Other interpreters and operating systems were not run. The isolated virtualenv has local test-tool additions and read-only access to existing site packages.
AI assistance: OpenAI Codex investigated the implementation and history, prepared the patch and tests, and ran validation with independent automated review. No human code review is claimed.
Maintenance validation (2026-11-17)
Merged upstream master while retaining the original iterator-matcher fix. Only CHANGES needed conflict resolution; the new Python support entry and this fix are both retained. On Windows CPython 3.11.18, the full suite passes: 269 passed (18 deprecation warnings). Both mypy modes and all applicable pre-commit hooks pass. Other Python versions and operating systems were not run in this maintenance check.