コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 9 of about 9 for testclient (0.004 sec.)
Test Client - TestClient 12115
Test Client - TestClient 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 Test ... ing . You can import it directly from fastapi.testclient : from fastapi.testclient import TestClient ::: fastapi.testclient.TestClient ...
https://man.mtool.work/fastapi/0.115/reference/testclient/
テスト 10964
テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を ... インポートします。 TestClient を作成し、 FastAPI に渡します。 test_ から始まる名前の関数を作成します (これは pytest の標準的なコンベンションです)。 http ... x と同じ様に TestClient オブジェクトを使用します。 チェックしたい Python の標準的な式と共に、シンプルに assert 文を記述します。 Python 3.8+ from f ... astapi import FastAPI from fastapi.testclient import TestClient app = FastAPI () @app . get ( "/" ) async def read_main (): return { "msg" : "Hello World" } client = Te ...
https://man.mtool.work/fastapi/0.115/tutorial/testing/
Testing WebSockets 9922
Testing WebSockets Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use the same TestClient to test WebSockets. For this, you use the TestClient in a with s ... tatement, connecting to the WebSocket: Python 3.8+ from fastapi import FastAPI from fastapi.testclient import TestClient from fastapi.websockets import WebSocket app = FastAPI () @app . get ( "/" ) async def read_main (): ret ... () await websocket . send_json ({ "msg" : "Hello WebSocket" }) await websocket . close () def test_read_main (): client = TestClient ( app ) response = client . get ( "/" ) assert response . status_code == 200 assert response . json () == { "msg" : "Hello ... World" } def test_websocket (): client = TestClient ( app ) with client . websocket_connect ( "/ws" ) as websocket : data = websocket . receive_json () assert data == { "msg" ...
https://man.mtool.work/fastapi/0.115/advanced/testing-websockets/
Testing Dependencies with Overrides 9616
Testing Dependencies with Overrides Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Overriding dependencies during testing There are some scenarios where you might ... d of the original dependency. Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI from fastapi.testclient import TestClient app = FastAPI () async def common_parameters ( q : str | None = None , skip : int = 0 , limit : int = 10 ... : Annotated [ dict , Depends ( common_parameters )]): return { "message" : "Hello Users!" , "params" : commons } client = TestClient ( app ) async def override_dependency ( q : str | None = None ): return { "q" : q , "skip" : 5 , "limit" : 10 } app . depe ... otated Python 3.8+ - non-Annotated from typing import Annotated , Union from fastapi import Depends , FastAPI from fastapi.testclient import TestClient app = FastAPI () async def common_parameters ( q : Union [ str , None ] = None , skip : int = 0 , limit ...
https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
Testing Events: startup - shutdown 8843
Testing Events: startup - shutdown Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . When you need your event handlers ( startup and shutdown ) to run in your tests, ... you can use the TestClient with a with statement: Python 3.8+ from fastapi import FastAPI from fastapi.testclient import TestClient app = FastAPI () ... get ( "/items/ {item_id} " ) async def read_items ( item_id : str ): return items [ item_id ] def test_read_items (): with TestClient ( app ) as client : response = client . get ( "/items/foo" ) assert response . status_code == 200 assert response . json ( ...
https://man.mtool.work/fastapi/0.115/advanced/testing-events/
Async Tests 8484
Async Tests Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You have already seen how to test your FastAPI applications using the provided TestClient . Up to now, ... your FastAPI application uses normal def functions instead of async def , it is still an async application underneath. The TestClient does some magic inside to call the asynchronous FastAPI application in your normal def test functions, using standard pyte ... k anymore when we're using it inside asynchronous functions. By running our tests asynchronously, we can no longer use the TestClient inside our test functions. The TestClient is based on HTTPX , and luckily, we can use it directly to test the API. Example ... == { "message" : "Tomato" } Tip Note that the test function is now async def instead of just def as before when using the TestClient . Then we can create an AsyncClient with the app, and send async requests to it, using await . Python 3.8+ import pytest f ...
https://man.mtool.work/fastapi/0.115/advanced/async-tests/
Settings and Environment Variables 7909
Settings and Environment Variables Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In many cases your application could need some external settings or configuratio ... ttings object during testing by creating a dependency override for get_settings : Python 3.8+ - non-Annotated from fastapi.testclient import TestClient from .config import Settings from .main import app , get_settings client = TestClient ( app ) def get_se ... "testing_admin@example.com" , "items_per_user" : 50 , } ? Other versions and variants Python 3.9+ Python 3.8+ from fastapi.testclient import TestClient from .config import Settings from .main import app , get_settings client = TestClient ( app ) def get_se ... ata == { "app_name" : "Awesome API" , "admin_email" : "testing_admin@example.com" , "items_per_user" : 50 , } from fastapi.testclient import TestClient from .config import Settings from .main import app , get_settings client = TestClient ( app ) def get_se ...
https://man.mtool.work/fastapi/0.115/advanced/settings/
FastAPI 6524
FastAPI FastAPI framework, high performance, easy to learn, fast to code, ready for production ドキュメント : https://fastapi.tiangolo.com ソースコード : https://github.com/fastapi/fastapi FastAPI は、Pythonの標準である型ヒントに基づいてPyt ... ションの依存関係 Pydantic によって使用されるもの: email-validator - E メールの検証 Starlette によって使用されるもの: httpx - TestClient を使用するために必要です。 jinja2 - デフォルトのテンプレート設定を使用する場合は必要です。 python-multipart - "parsing" re ...
https://man.mtool.work/fastapi/0.115/
Release Notes 6435
Release Notes Latest Changes 0.115.11 Fixes ? Add docs examples and tests (support) for Annotated custom validations, like AfterValidator , revert #13440 . PR #13442 by @tiangolo . New docs: Query Parameters and String Validations - Custom ... docs/de/docs/reference/staticfiles.md . PR #10841 by @nilslindemann . ? Add German translation for docs/de/docs/reference/testclient.md . PR #10843 by @nilslindemann . ? Add German translation for docs/de/docs/project-generation.md . PR #10851 by @nilslin ...
https://man.mtool.work/fastapi/0.115/release-notes/
PREV 1 NEXT