Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import inspect
from pathlib import Path
from unittest.mock import Mock

import aiohttp
import pytest
from responses import RequestsMock

here = Path(__file__).parent


# Cribbed from https://github.com/j7an/dep-rank/pull/123
# aiohttp 3.14 added a required keyword-only ``stream_writer`` argument to
# ``ClientResponse.__init__``. aioresponses (<=0.7.8) builds mocked responses
# without it, so every mocked request raises ``TypeError: ... missing 1
# required keyword-only argument: 'stream_writer'``. aiohttp only reads
# ``stream_writer.output_size``, so a ``Mock(output_size=0)`` suffices.
#
# This mirrors the upstream fix (aioresponses#288, tracking aioresponses#289).
# The signature guard makes it a no-op on aiohttp < 3.14 and once aioresponses
# ships a release that supplies the argument itself; remove this shim then.
_response_init = aiohttp.ClientResponse.__init__
if "stream_writer" in inspect.signature(_response_init).parameters:

def _patched_response_init(self, *args, **kwargs): # type: ignore[no-untyped-def]
kwargs.setdefault("stream_writer", Mock(output_size=0))
_response_init(self, *args, **kwargs)

aiohttp.ClientResponse.__init__ = _patched_response_init


@pytest.fixture
def responses():
with RequestsMock() as rsps:
Expand Down
Loading