Using pdb for errors thrown inside Datasette

Closes #1207
pull/1211/head
Simon Willison 2021-01-28 18:12:32 -08:00 zatwierdzone przez GitHub
rodzic 1600d2a3ec
commit dde3c500c7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 19 dodań i 0 usunięć

Wyświetl plik

@ -51,6 +51,25 @@ Then run the tests using pytest like so::
pytest
.. _testing_plugins_pdb:
Using pdb for errors thrown inside Datasette
--------------------------------------------
If an exception occurs within Datasette itself during a test, the response returned to your plugin will have a ``response.status_code`` value of 500.
You can add ``pdb=True`` to the ``Datasette`` constructor to drop into a Python debugger session inside your test run instead of getting back a 500 response code. This is equivalent to running the ``datasette`` command-line tool with the ``--pdb`` option.
Here's what that looks like in a test function:
.. code-block:: python
def test_that_opens_the_debugger_or_errors():
ds = Datasette([db_path], pdb=True)
response = await ds.client.get("/")
If you use this pattern you will need to run ``pytest`` with the ``-s`` option to avoid capturing stdin/stdout in order to interact with the debugger prompt.
.. _testing_plugins_fixtures:
Using pytest fixtures