Skip to content

Stabilize the test suite#183

Open
mcepl wants to merge 1 commit into
h2non:masterfrom
openSUSE-Python:stabilize_tests
Open

Stabilize the test suite#183
mcepl wants to merge 1 commit into
h2non:masterfrom
openSUSE-Python:stabilize_tests

Conversation

@mcepl

@mcepl mcepl commented Jul 8, 2026

Copy link
Copy Markdown

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.

PR Checklist

  • I've added tests for any code changes (this is all about fixing the test suite, so not completely relevant)
  • I've documented any new features (there are no new futures)

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.
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