Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host parameter to aiohttp_server fixture. #10120

Closed
1 task done
christianwbrock opened this issue Dec 5, 2024 · 2 comments · Fixed by #10121
Closed
1 task done

Add host parameter to aiohttp_server fixture. #10120

christianwbrock opened this issue Dec 5, 2024 · 2 comments · Fixed by #10121

Comments

@christianwbrock
Copy link
Contributor

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
@Dreamsorcerer
Copy link
Member

I think that's reasonable, feel free to make a PR.

@christianwbrock
Copy link
Contributor Author

Dreamsorcerer pushed a commit that referenced this issue Dec 9, 2024
Co-authored-by: ChristianWBrock <christian.brock AT posteo.net>
Dreamsorcerer pushed a commit that referenced this issue Dec 9, 2024
Co-authored-by: ChristianWBrock <christian.brock AT posteo.net>
(cherry picked from commit 7f8e2d3)
Dreamsorcerer added a commit that referenced this issue Dec 9, 2024
Co-authored-by: ChristianWBrock <christian.brock AT posteo.net>
(cherry picked from commit 7f8e2d3)

Co-authored-by: christianwbrock <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants