From 8b25b14de17e50edca4f5a5fe8001587d9e4006c Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 28 Jun 2020 09:09:43 -0700 Subject: [PATCH] Added note about unit testing the startup() hook --- docs/plugin_hooks.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/plugin_hooks.rst b/docs/plugin_hooks.rst index 8683bee8..ccd4ca3d 100644 --- a/docs/plugin_hooks.rst +++ b/docs/plugin_hooks.rst @@ -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 ` 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 `__ .. _plugin_hook_canned_queries: