Bubbling up exceptions in test cases

I would like to receive exceptions straight from my endpoints’ code rather than receiving a 500 response and trying to manually debug what happened.

Is this possible?

I couldn’t find anything in the docs or searching online.

Catching of exceptions is built in pretty hard because asyncio protocol would silently ignore them and other servers are likely to crash, neither of which is acceptable even when debugging (normally you want to keep the server running, listening for the next request). There is no straight-forward way to bubble them out, but perhaps you could hook to exception handling and extract the stack information, local variables or whatever you might need from each stack frame.

Sanic’s debug mode already provides a traceback on its error pages but it might later be replaced with https://github.com/Tronic/niceback which also lists local variables and other information.

Would those be sufficient for your use, or what sort of debugging do you have in mind specifically?

Here’s an example of what I have in mind. I would like to have a setup that allows this test case to pass:

import pytest
from pytest import raises
from pytest_sanic.utils import TestClient
from sanic import Sanic
from sanic.request import Request

def app():
    app = Sanic()

    async def raise_error(request: Request) -> int:
        return 1 / 0

    yield app

def client(loop, app, sanic_client):
    return loop.run_until_complete(sanic_client(app))

async def test_exception(client: TestClient) -> None:
    with raises(ZeroDivisionError):
        await client.get("/error")

Are there any updates on this?