Results of 1 - 1 of about 1 for Tomato (0.000 sec.)
- Async Tests 9414
- 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,
...have: Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def root (): return { "message" : "Tomato" } The file test_main.py would have the tests for main.py , it could look like this now: Python 3.8+ import pytest from ht...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 via: $ pytest ---> 100% In Detail The marker @pytest.mark.anyio tells pytest tha...as ac : response = await ac . get ( "/" ) assert response . status_code == 200 assert response . json () == { "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... - https://man.mtool.work/fastapi/0.115/advanced/async-tests/
PREV
1
NEXT