Skip to content

Commit 880c28f

Browse files
committed
test: monkeypatch ClientResponse.__init__ to support latest aiohttp versions with aioresponses
1 parent 29aac34 commit 880c28f

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ classifiers = [
4141
"Operating System :: OS Independent",
4242
]
4343
dependencies = [
44-
"aiohttp<3.14",
44+
"aiohttp",
4545
"cryptography>=42.0.0",
4646
"dnspython>=2.0.0",
4747
"Requests",

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"""
1616

1717
import asyncio
18+
import inspect
1819
import os
1920
import socket
2021
import ssl
2122
from threading import Thread
2223
from typing import Any, AsyncGenerator
2324

25+
import aiohttp
2426
from aiohttp import web
2527
from cryptography.hazmat.primitives import serialization
2628
import pytest # noqa F401 Needed to run the tests
@@ -35,6 +37,19 @@
3537
from google.cloud.sql.connector.utils import generate_keys
3638
from google.cloud.sql.connector.utils import write_to_file
3739

40+
# Monkeypatch aiohttp.ClientResponse.__init__ to support aioresponses with aiohttp >= 3.11/3.14
41+
_original_client_response_init = aiohttp.ClientResponse.__init__
42+
43+
44+
def _patched_client_response_init(self, *args, **kwargs):
45+
sig = inspect.signature(_original_client_response_init)
46+
if "stream_writer" in sig.parameters and "stream_writer" not in kwargs:
47+
kwargs["stream_writer"] = kwargs.get("writer", None)
48+
return _original_client_response_init(self, *args, **kwargs)
49+
50+
51+
aiohttp.ClientResponse.__init__ = _patched_client_response_init
52+
3853
SCOPES = ["https://www.googleapis.com/auth/sqlservice.admin"]
3954

4055

0 commit comments

Comments
 (0)