Can't see exception tracebacks in pytest with TestClient #2009
-
Hi there Nice framework. It's been interesting to see pieces coming together over time, and it's starting to click overall for me. When testing with pytest, if there's an unhandled exception raised that leads to a server error, I'd expect to see a traceback in pytest that helps me pinpoint the nature of the exception that was raised. But all I'm seeing is that the status code was 500, which doesn't especially help me. I wind up being better off spinning up the app with uvicorn and trying to recreate it there, but that's much slower, especially if it wound up being a cause that needed a lot of steps to recreate. Am I missing something? Details below: versionspip freeze | grep litestar
litestar==2.0.0b2 pip freeze | grep pytest
pytest==7.4.0 samplefrom litestar import Litestar, get
from litestar.testing import TestClient
@get("")
def raise_something() -> str:
raise Exception("A bad thing happened")
app = Litestar(
route_handlers=[raise_something]
)
client = TestClient(app)
def test_that_fails():
response = client.get("")
assert response.status_code == 200 commandpytest test_sample.py output
ExpectedI would have expected the above pytest output to include a traceback that pinpoints the line of code where the issue occurred. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You can set @provinzkraut - we should switch testing to use debug by default. |
Beta Was this translation helpful? Give feedback.
You can set
debug=True
in your test client and that will give you a traceback.@provinzkraut - we should switch testing to use debug by default.