Results of 1 - 6 of about 6 for assert (0.002 sec.)
- テスト 11936
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...ンションです)。 httpx と同じ様に TestClient オブジェクトを使用します。 チェックしたい Python の標準的な式と共に、シンプルに assert 文を記述します。 Python 3.8+ from fastapi import FastAPI from fastapi.testclient import TestClient app = FastAPI () @app ....in (): return { "msg" : "Hello World" } client = TestClient ( app ) def test_read_main (): response = client . get ( "/" ) assert response . status_code == 200 assert response . json () == { "msg" : "Hello World" } 豆知識 テスト関数は async def ではなく...import TestClient from .main import app client = TestClient ( app ) def test_read_main (): response = client . get ( "/" ) assert response . status_code == 200 assert response . json () == { "msg" : "Hello World" } テスト: 例の拡張 次に、この例を拡張し... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- Testing Dependencies with Overrides 11351
- 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
...overrides [ common_parameters ] = override_dependency def test_override_in_items (): response = client . get ( "/items/" ) assert response . status_code == 200 assert response . json () == { "message" : "Hello Items!" , "params" : { "q" : None , "skip"...: 5 , "limit" : 10 }, } def test_override_in_items_with_q (): response = client . get ( "/items/?q=foo" ) assert response . status_code == 200 assert response . json () == { "message" : "Hello Items!" , "params" : { "q" : "foo" , "skip...limit" : 10 }, } def test_override_in_items_with_params (): response = client . get ( "/items/?q=foo&skip=100&limit=200" ) assert response . status_code == 200 assert response . json () == { "message" : "Hello Items!" , "params" : { "q" : "foo" , "skip... - https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
- Async Tests 8426
- 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,
...syncClient ( transport = ASGITransport ( app = app ), base_url = "http://test" ) as ac : response = await ac . get ( "/" ) assert response . status_code == 200 assert response . json () == { "message" : "Tomato" } Run it You can run your tests as usual...syncClient ( transport = ASGITransport ( app = app ), base_url = "http://test" ) as ac : response = await ac . get ( "/" ) assert response . status_code == 200 assert response . json () == { "message" : "Tomato" } Tip Note that the test function is now...syncClient ( transport = ASGITransport ( app = app ), base_url = "http://test" ) as ac : response = await ac . get ( "/" ) assert response . status_code == 200 assert response . json () == { "message" : "Tomato" } This is the equivalent to: response =... - https://man.mtool.work/fastapi/0.115/advanced/async-tests/
- Testing WebSockets 8152
- 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
...ebSocket" }) 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 = TestC...lient ( app ) with client . websocket_connect ( "/ws" ) as websocket : data = websocket . receive_json () assert data == { "msg" : "Hello WebSocket" } Note For more details, check Starlette's documentation for testing WebSockets .... - https://man.mtool.work/fastapi/0.115/advanced/testing-websockets/
- Testing Events: startup - shutdown 7732
- 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,
...urn 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 () == { "name" : "Fighters" }... - https://man.mtool.work/fastapi/0.115/advanced/testing-events/
- Settings and Environment Variables 7183
- 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
...es [ get_settings ] = get_settings_override def test_app (): response = client . get ( "/info" ) data = response . json () assert data == { "app_name" : "Awesome API" , "admin_email" : "testing_admin@example.com" , "items_per_user" : 50 , } ? Other ver...es [ get_settings ] = get_settings_override def test_app (): response = client . get ( "/info" ) data = response . json () assert data == { "app_name" : "Awesome API" , "admin_email" : "testing_admin@example.com" , "items_per_user" : 50 , } from fastap...es [ get_settings ] = get_settings_override def test_app (): response = client . get ( "/info" ) data = response . json () assert data == { "app_name" : "Awesome API" , "admin_email" : "testing_admin@example.com" , "items_per_user" : 50 , } In the depe... - https://man.mtool.work/fastapi/0.115/advanced/settings/
PREV
1
NEXT