-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
pytest hangs with trivial example #92
Comments
So, yes, if Runnable script with Ruff below # /// script
# requires-python = ">=3.9"
# dependencies = [
# "fastapi",
# "httpx-ws",
# ]
# ///
import asyncio
from fastapi import FastAPI, WebSocket
from httpx import AsyncClient
import httpx_ws
from httpx_ws.transport import ASGIWebSocketTransport
app = FastAPI()
SHOW_HANG = True
@app.websocket("/ws")
async def websocket_endpoint(ws: WebSocket) -> None:
if not SHOW_HANG:
await ws.accept()
return
async def test_basics() -> None:
async with AsyncClient(
transport=ASGIWebSocketTransport(app), base_url="http://test"
) as client:
async with httpx_ws.aconnect_ws("http://test/ws", client) as ws:
assert True
if __name__ == "__main__":
asyncio.run(test_basics()) |
always hangs? 🤔 |
I admit it’s not a bug. But it can occur unexpectedly (as happened to me) and the messages printed after ctrl-c are not at all helpful. Even improving those would be a big help |
Yes, I see 🤔 Then yes, open to add a reasonable timeout on the first httpx-ws/httpx_ws/transport.py Line 50 in fedb69d
|
Describe the bug
I have been having a lot of problems with pytest hanging when trying to test a fastapi server.
I finally narrowed down one clear case (though I think I am facing others, as well): if the websocket endpoint returns without accepting the websocket then the test will hang.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I should be able to run tests using pytest without the test hanging.
Configuration
Additional context
Add any other context about the problem here.
test_trivial_hang.py.zip
The text was updated successfully, but these errors were encountered: