Skip to content

Broken timeout #2657

@karpetrosyan

Description

@karpetrosyan

timeout argument doesn't work

server.py

import asyncio
from fastapi import FastAPI

app = FastAPI()

@app.get("/slow_response")
async def slow_request():
    await asyncio.sleep(10)

test.py

@pytest.mark.anyio
async def test_timeout_exception(app):
    async with httpx.AsyncClient(app=app, base_url="https://example.com", timeout=1) as client:
        await client.get("/slow_response", timeout=1)
$ time pytest tests/test_downloader.py::test_timeout_exception 
.                                                                                                                                                                                                                           [100%]
1 passed in 10.11s
pytest tests/test_downloader.py::test_timeout_exception -q  0.58s user 0.07s system 6% cpu 10.665 total

How this works? The request takes 10 seconds but it works fine with 1 second timeout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions