- Sort Score
- Num 10 results
- Language All
Results 1 - 10 of 256 for TestClient (0.18 seconds)
-
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: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Apr 18 19:53:19 GMT 2024 - 450 bytes - Click Count (0) -
fastapi/testclient.py
from starlette.testclient import TestClient as TestClient # noqa...
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Dec 20 18:50:00 GMT 2020 - 66 bytes - Click Count (0) -
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: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 05 18:23:16 GMT 2026 - 5.2K bytes - Click Count (0) -
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: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Wed Dec 17 21:25:59 GMT 2025 - 2.2K bytes - Click Count (0) -
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: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sat Dec 20 15:55:38 GMT 2025 - 2.1K bytes - Click Count (0) -
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: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Feb 08 10:18:38 GMT 2026 - 3.8K bytes - Click Count (0) -
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: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Feb 22 16:34:59 GMT 2026 - 2K bytes - Click Count (0) -
docs_src/app_testing/tutorial003_py310.py
from fastapi import FastAPI from fastapi.testclient import TestClient app = FastAPI() items = {} @app.on_event("startup") async def startup_event(): items["foo"] = {"name": "Fighters"} items["bar"] = {"name": "Tenders"} @app.get("/items/{item_id}") async def read_items(item_id: str): return items[item_id] def test_read_items(): with TestClient(app) as client:
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 528 bytes - Click Count (0) -
tests/test_orjson_response_class.py
import warnings from fastapi import FastAPI from fastapi.exceptions import FastAPIDeprecationWarning from fastapi.responses import ORJSONResponse from fastapi.testclient import TestClient from sqlalchemy.sql.elements import quoted_name with warnings.catch_warnings(): warnings.simplefilter("ignore", FastAPIDeprecationWarning) app = FastAPI(default_response_class=ORJSONResponse) @app.get("/orjson_non_str_keys")
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Feb 22 16:34:59 GMT 2026 - 846 bytes - Click Count (0) -
tests/test_openapi_cache_root_path.py
from fastapi import FastAPI from fastapi.testclient import TestClient def test_root_path_does_not_persist_across_requests(): app = FastAPI() @app.get("/") def read_root(): # pragma: no cover return {"ok": True} # Attacker request with a spoofed root_path attacker_client = TestClient(app, root_path="/evil-api") response1 = attacker_client.get("/openapi.json") data1 = response1.json()
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Tue Feb 24 09:28:10 GMT 2026 - 2.3K bytes - Click Count (0)