Tests fail: aioresponses + aiohttp 3.14
All checks were successful
PR Tests / test (pull_request) Successful in 59s
NYX Security Scan / nyx-scan (pull_request) Successful in 6m24s

Co-authored-by: alpha-nerd <alpha-nerd@users.noreply.bitfreedom.net>
This commit is contained in:
opencode-agent[bot] 2026-06-02 06:52:53 +00:00
parent 0ebd999409
commit 8dad944ebc

View file

@ -24,6 +24,51 @@ import aiohttp
import httpx
import pytest
# ── Patch aioresponses for aiohttp 3.14.0 compatibility ──────────────────────
# aiohttp 3.14.0 added a required `stream_writer` parameter to
# `ClientResponse.__init__()`. The released `aioresponses==0.7.8` does not pass
# this argument, causing:
# TypeError: ClientResponse.__init__() missing 1 required keyword-only argument:
# 'stream_writer'
#
# We monkey-patch `ClientResponse.__init__` to accept `stream_writer` with a
# default value when called from aioresponses (i.e. when `writer` is None).
try:
from aiohttp.client_reqrep import ClientResponse
_ClientResponse__init__ = ClientResponse.__init__
def _patched_client_response_init(
self,
method,
url,
*,
writer,
continue100,
timer,
request_info,
traces,
loop,
session,
stream_writer=None, # type: ignore[assignment]
):
# If stream_writer was not provided (aioresponses 0.7.8), create a mock.
# When writer is None (mocked response), stream_writer.output_size is read.
if writer is None and stream_writer is None:
mock_writer = MagicMock()
mock_writer.output_size = 0
stream_writer = mock_writer
return _ClientResponse__init__(
self, method, url, writer=writer, continue100=continue100,
timer=timer, request_info=request_info, traces=traces,
loop=loop, session=session, stream_writer=stream_writer,
)
ClientResponse.__init__ = _patched_client_response_init # type: ignore[assignment]
except Exception:
pass # If patching fails, tests will fail with a clear TypeError instead
_TEST_DIR = Path(__file__).parent
# Must be set before importing router so module-level Config.from_yaml + Config field
# defaults pick these up. db_path is intentionally absent from config_test.yaml so the