Added note about unit testing the startup() hook

pull/868/head
Simon Willison 2020-06-28 09:09:43 -07:00
rodzic b28657672f
commit 8b25b14de1
1 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -705,6 +705,18 @@ Potential use-cases:
* Create database tables that a plugin needs on startup
* Validate the metadata configuration for a plugin on startup, and raise an error if it is invalid
.. note::
If you are writing :ref:`unit tests <testing_plugins>` for a plugin that uses this hook you will need to explicitly call ``await ds.invoke_startup()`` in your tests. An example:
.. code-block:: python
@pytest.mark.asyncio
async def test_my_plugin():
ds = Datasette([], metadata={})
await ds.invoke_startup()
# Rest of test goes here
Example: `datasette-saved-queries <https://github.com/simonw/datasette-saved-queries>`__
.. _plugin_hook_canned_queries: