Skip to content

Add host parameter to aiohttp_server fixture. #10120

@christianwbrock

Description

@christianwbrock

Is your feature request related to a problem?

I develop code that accesses 3rd party services available as docker images.

When testing my code using the aiohttp pytest plugin the following needs to happen:

  • I create a server using the aiohttp_server fixture.
  • I call the service running in the docker container and ...
  • ... pass the aiohttp_server's URL as callback URL.
  • The docker service tries to send me some data.
  • For the docker container to reach the host it needs to use either the host IP or 172.17.0.1.

What happens is that aiohttp_server is unreachable.

This happens because:

  • aiohttp_server calls TestServer(app, port=port) -- in aiohttp/pytest_plugin.py line 309
  • TestServer.__init__() has a default value host='127.0.0.1' in aiohttp/test_utils.py` line 227

Describe the solution you'd like

Change lines 306ff in aiohttp.pytest_plugin.py from

    async def go(
        app: Application, *, port: Optional[int] = None, **kwargs: Any
    ) -> TestServer:
        server = TestServer(app, port=port)

to

    async def go(
        app: Application, *, host: Optional[str] = '127.0.0.1', port: Optional[int] = None, **kwargs: Any
    ) -> TestServer:
        server = TestServer(app, host=host, port=port)

Describe alternatives you've considered

I created my own fixture, a copy of aiohttp_server with the fix applied.

Related component

Server

Additional context

The releated component selected above is misleading, as only the pytest plugin is affected.

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions