Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
How to disable server exceptions on fast-api when testing with httpx AsyncClient?

We have a FastApi app and using httpx AsyncClient for testing purposes. We are experiencing a problem where the unit tests run locally fine but fail on the CI server (Github Actions).

After further research we have come across this proposed solution by setting raise_server_exceptions=False to False.

client = TestClient(app, raise_server_exceptions=False)

However this is for the sync client. We are using the async client.

@pytest.fixture
async def client(test_app):
    async with AsyncClient(app=test_app, base_url="http://testserver") as client:
        yield client

The AsyncClient does not support the raise_app_exceptions=False option.

Does anyone have experience with this? Thanks

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The problem is caused by FastApi version. You can use fastapi==0.65.0 and even without the ASGITransport object and the raise_app_exceptions=False flag you will be able to run the tests which are checking for custom exception raising. Also the fastapi version should be frozen in the requirements file. You ca read more here

over 4 years ago · Santiago Trujillo Relatório

0

For httpx v0.14.0+ you need to use httpx.ASGITransport. Excerpt from the official documentation:

For some more complex cases you might need to customise the ASGI transport. This allows you to:

  • Inspect 500 error responses rather than raise exceptions by setting raise_app_exceptions=False.
  • Mount the ASGI application at a subpath by setting root_path.
  • Use a given client address for requests by setting client.

For example:

# Instantiate a client that makes ASGI requests with a client IP of "1.2.3.4",
# on port 123.
transport = httpx.ASGITransport(app=app, raise_app_exceptions=False,
 client=("1.2.3.4", 123))
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
    ...
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda