Stabilize the test suite#183
Open
mcepl wants to merge 1 commit into
Open
Conversation
This PR stabilizes `pook`'s patching mechanisms for modern runtimes (Python 3.13+) and newer third-party package APIs: - **Robust `mock.patch` helper (`resolve_path`):** Replaced calls to the undocumented/internal `patcher.get_original()` method with a robust dynamic resolver (`resolve_path`). This safely resolves original, unpatched target objects before `unittest.mock.patch` wraps them. - **Graceful Optional Dependencies:** All resolving and patching are safely wrapped inside `try...except Exception: pass` blocks, preserving `pook`'s clean fallback behavior in environments where optional clients (like `httpx` or `urllib3`) are not installed. - **Fixed `aiohttp` compatibility:** Added dynamic signature inspection to `session._response_class.__init__` to gracefully supply a mock `stream_writer` argument. This directly resolves `TypeError: ClientResponse.__init__() missing 1 required keyword-only argument: 'stream_writer'` failures on newer `aiohttp >= 3.9` releases. - **Refactored `headers.py` assertions:** Converted fragile `assert` statements into explicit `if not ...: raise AssertionError(...)` blocks, ensuring validation logic is consistently executed and not stripped out under Python's optimized mode (`-O`). Recent changes to internal Python mocking details and third-party package APIs (like `aiohttp`) broke `pook`'s interceptors. This patch resolves these issues cleanly and ensures full compatibility without introducing hard dependency requirements on optional HTTP clients.
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.
This PR stabilizes
pook's patching mechanisms for modern runtimes (Python 3.13+) and newer third-party package APIs:mock.patchhelper (resolve_path): Replaced calls to the undocumented/internalpatcher.get_original()method with a robust dynamic resolver (resolve_path). This safely resolves original, unpatched target objects beforeunittest.mock.patchwraps them.try...except Exception: passblocks, preservingpook's clean fallback behavior in environments where optional clients (likehttpxorurllib3) are not installed.aiohttpcompatibility: Added dynamic signature inspection tosession._response_class.__init__to gracefully supply a mockstream_writerargument. This directly resolvesTypeError: ClientResponse.__init__() missing 1 required keyword-only argument: 'stream_writer'failures on neweraiohttp >= 3.9releases.headers.pyassertions: Converted fragileassertstatements into explicitif not ...: raise AssertionError(...)blocks, ensuring validation logic is consistently executed and not stripped out under Python's optimized mode (-O).Recent changes to internal Python mocking details and third-party package APIs (like
aiohttp) brokepook's interceptors. This patch resolves these issues cleanly and ensures full compatibility without introducing hard dependency requirements on optional HTTP clients.PR Checklist