Skip to content
Discussion options

You must be logged in to vote

One thing which worked for me was to add the argument raise_server_exceptions which is by default set to True in the test client:

client = TestClient(app, raise_server_exceptions=False)

I'm using fastapi 0.68.1 which installs startlette 0.14.2, so I do not know if this option is available for earlier version...

So the whole snippet is

from fastapi import FastAPI
from fastapi.testclient import TestClient
from fastapi.exceptions import HTTPException

app = FastAPI()


@app.get("/")
async def read_main():
    return do_hello()

def do_hello():
    return {"msg": "Hello World"}


### Test

client = TestClient(app, raise_server_exceptions=False)


def test_read_main():
    response = client.g…

Replies: 8 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JCHacking
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
8 participants
Converted from issue

This discussion was converted from issue #2799 on February 28, 2023 17:17.