Testing an API End to End
Testing an API End to End: Testing an API with TestClient, Testing Errors, with a Fresh Start for Every Test.
Updated
- Testing an API with TestClient (Journeyman): FastAPI's TestClient hands a request straight to your app, with no server running and no port, so a pytest test can check the status code, a header and the JSON body that come back, for a GET and for a POST with a body.
- Testing Errors, with a Fresh Start for Every Test (Journeyman): Tests for an API's error answers check the status code, the whole error body and that nothing changed, @pytest.mark.parametrize runs one test for each bad value, and an autouse fixture that resets the data gives every test the same fresh start, so the tests pass alone and in any order.