Skip to content

AsyncClient cookie not being persisted #2143

@cp-weng

Description

@cp-weng
# app.py
@router.post("/login")
async def login(response: Response):
    # ...omit
    response.set_cookie(
        key=ACCESS_TOKEN_COOKIE_KEY,
        value=token_value,
    )
    return ...

# conftest.py
@pytest.fixture()
async def async_client(app: FastAPI) -> AsyncGenerator:
    async with AsyncClient(app=app, base_url="http://test") as ac:
        yield ac

# test_blablabla.py
async def test_login(async_client):
    response = await async_client.post("/login", json={...})
    # `response.cookies` is empty here and not being persisted

Expected

As the docs says, response.cookies should contain access token

Actual

response.cookies is empty

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