mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Added note about unit testing the startup() hook
This commit is contained in:
parent
b28657672f
commit
8b25b14de1
1 changed files with 12 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue