Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 324 for TestClient (0.06 seconds)

  1. docs/en/docs/reference/testclient.md

    You can use the `TestClient` class to test FastAPI applications without creating an actual HTTP and socket connection, just communicating directly with the FastAPI code.
    
    Read more about it in the [FastAPI docs for Testing](https://fastapi.tiangolo.com/tutorial/testing/).
    
    You can import it directly from `fastapi.testclient`:
    
    ```python
    from fastapi.testclient import TestClient
    ```
    
    Created: 2026-04-05 07:19
    - Last Modified: 2024-04-18 19:53
    - 450 bytes
    - Click Count (0)
  2. fastapi/testclient.py

    from starlette.testclient import TestClient as TestClient  # noqa...
    Created: 2026-04-05 07:19
    - Last Modified: 2020-12-20 18:50
    - 66 bytes
    - Click Count (0)
  3. tests/benchmarks/test_general_performance.py

    ):
        return ItemOut(name="foo", value=123, dep=dep)
    
    
    @pytest.fixture(scope="module")
    def client() -> Iterator[TestClient]:
        with TestClient(app) as client:
            yield client
    
    
    def _bench_get(benchmark, client: TestClient, path: str) -> tuple[int, bytes]:
        warmup = client.get(path)
        assert warmup.status_code == 200
    
        def do_request() -> tuple[int, bytes]:
    Created: 2026-04-05 07:19
    - Last Modified: 2025-12-26 20:40
    - 11.1K bytes
    - Click Count (0)
  4. tests/test_request_params/test_form/test_optional_list.py

    from typing import Annotated
    
    import pytest
    from fastapi import FastAPI, Form
    from fastapi.testclient import TestClient
    from pydantic import BaseModel, Field
    
    from .utils import get_body_model_name
    
    app = FastAPI()
    
    # =====================================================================================
    # Without aliases
    
    
    @app.post("/optional-list-str", operation_id="optional_list_str")
    async def read_optional_list_str(
    Created: 2026-04-05 07:19
    - Last Modified: 2026-02-17 09:59
    - 9.9K bytes
    - Click Count (0)
  5. tests/test_tutorial/test_body_nested_models/test_tutorial005.py

    import importlib
    
    import pytest
    from dirty_equals import IsList
    from fastapi.testclient import TestClient
    from inline_snapshot import snapshot
    
    from ...utils import needs_py310
    
    
    @pytest.fixture(
        name="client",
        params=[
            pytest.param("tutorial005_py310", marks=needs_py310),
        ],
    )
    def get_client(request: pytest.FixtureRequest):
        mod = importlib.import_module(f"docs_src.body_nested_models.{request.param}")
    
    Created: 2026-04-05 07:19
    - Last Modified: 2026-02-12 13:19
    - 10.3K bytes
    - Click Count (0)
  6. tests/test_response_dependency.py

    """
    
    from typing import Annotated
    
    from fastapi import BackgroundTasks, Depends, FastAPI, Request, Response
    from fastapi.responses import JSONResponse
    from fastapi.testclient import TestClient
    
    
    def test_response_with_depends_annotated():
        """Response type hint should work with Annotated[Response, Depends(...)]."""
        app = FastAPI()
    
        def modify_response(response: Response) -> Response:
    Created: 2026-04-05 07:19
    - Last Modified: 2026-02-05 18:23
    - 5.2K bytes
    - Click Count (0)
  7. tests/test_stringified_annotation_dependency.py

    
    @pytest.fixture(name="client")
    def client_fixture() -> TestClient:
        app = FastAPI()
    
        @app.get("/")
        async def get_people(client: Client) -> list:
            return await client.get_people()
    
        client = TestClient(app)
        return client
    
    
    def test_get(client: TestClient):
        response = client.get("/")
        assert response.status_code == 200, response.text
    Created: 2026-04-05 07:19
    - Last Modified: 2025-12-17 21:25
    - 2.2K bytes
    - Click Count (0)
  8. tests/test_schema_ref_pydantic_v2.py

        async def read_root() -> Any:
            return {"$ref": "some-ref"}
    
        client = TestClient(app)
        return client
    
    
    def test_get(client: TestClient):
        response = client.get("/")
        assert response.json() == {"$ref": "some-ref"}
    
    
    def test_openapi_schema(client: TestClient):
        response = client.get("openapi.json")
        assert response.json() == snapshot(
            {
    Created: 2026-04-05 07:19
    - Last Modified: 2025-12-20 15:55
    - 2.1K bytes
    - Click Count (0)
  9. tests/test_computed_fields.py

    import pytest
    from fastapi import FastAPI
    from fastapi.testclient import TestClient
    from inline_snapshot import snapshot
    
    
    @pytest.fixture(name="client")
    def get_client(request):
        separate_input_output_schemas = request.param
        app = FastAPI(separate_input_output_schemas=separate_input_output_schemas)
    
        from pydantic import BaseModel, computed_field
    
        class Rectangle(BaseModel):
            width: int
            length: int
    
    Created: 2026-04-05 07:19
    - Last Modified: 2026-02-08 10:18
    - 3.8K bytes
    - Click Count (0)
  10. tests/test_deprecated_responses.py

    import warnings
    
    import pytest
    from fastapi import FastAPI
    from fastapi.exceptions import FastAPIDeprecationWarning
    from fastapi.responses import ORJSONResponse, UJSONResponse
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    
    class Item(BaseModel):
        name: str
        price: float
    
    
    # ORJSON
    
    
    def _make_orjson_app() -> FastAPI:
        with warnings.catch_warnings():
    Created: 2026-04-05 07:19
    - Last Modified: 2026-02-22 16:34
    - 2K bytes
    - Click Count (0)
Back to Top