Skip to content

Commit

Permalink
Adding test cases for traceback file name
Browse files Browse the repository at this point in the history
  • Loading branch information
sombek committed Dec 30, 2022
1 parent 202133b commit 411ad02
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/test_exception_handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from fastapi import FastAPI, HTTPException
from fastapi import Depends, FastAPI, HTTPException
from fastapi.exceptions import RequestValidationError
from fastapi.testclient import TestClient
from starlette.responses import JSONResponse
Expand Down Expand Up @@ -28,6 +28,15 @@ def server_error_exception_handler(request, exception):
client = TestClient(app)


def dependency_with_yield():
yield "This is a dependency with yield"


@app.get("/with-yield", dependencies=[Depends(dependency_with_yield)])
def with_yield():
raise RuntimeError("Should print traceback, with file and line number")


@app.get("/http-exception")
def route_with_http_exception():
raise HTTPException(status_code=400)
Expand Down Expand Up @@ -65,3 +74,11 @@ def test_override_server_error_exception_response():
response = client.get("/server-error")
assert response.status_code == 500
assert response.json() == {"exception": "server-error"}


def test_showing_exception_trace():
app.debug = True
client = TestClient(app, raise_server_exceptions=False)
response = client.get("/with-yield")
assert response.status_code == 500
assert __file__ in response.text

0 comments on commit 411ad02

Please sign in to comment.