Skip to content

AsyncClient cookie not being persisted #2143

Closed

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

Activity

  1. locked and limited conversation to collaborators on Mar 24, 2022
  2. converted this issue into a discussion #2144 on Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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