If you're writing tests for a Datasette plugin and you get a 500 error from inside Datasette, you can cause Datasette to open a PDB session within the application server code by doing this:
ds = Datasette([db_path], pdb=True)
response = await ds.client.get("/")
You'll need to run pytest -s to interact with the debugger, otherwise you'll get an error.