Skip to content

aioresponses ignores streaming uploads #270

@OvervCW

Description

@OvervCW

Consider the following example:

import asyncio

from aiohttp import ClientSession
from aioresponses import aioresponses


async def main():
    with aioresponses() as mock_responses:
        mock_responses.post("http://1.2.3.4")

        async def data_generator():
            yield b"foo"
            raise RuntimeError("this generator is never awaited")

        async with (
            ClientSession() as session,
            session.post("http://1.2.3.4", data=data_generator()) as response,
        ):
            print(response.status)
            print(await response.text())


if __name__ == "__main__":
    asyncio.run(main())

I would expect a failure here because the generator for the request body raises an exception, but instead the code exits normally with a 200 response. It seems like aioresponses is never actually awaiting the request body generator.

In my current project this is a problem because it means that there is no test coverage for the generator.

Is there a workaround for this, or is this a bug that needs to be fixed in aioresponses?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions