mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Replace AsgiLifespan with AsgiRunOnFirstRequest, refs #1955
This commit is contained in:
parent
89cffcf14c
commit
63fb750f39
4 changed files with 22 additions and 49 deletions
|
|
@ -902,13 +902,14 @@ Potential use-cases:
|
|||
|
||||
.. 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:
|
||||
If you are writing :ref:`unit tests <testing_plugins>` for a plugin that uses this hook and doesn't exercise Datasette by sending
|
||||
any simulated requests through it 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={})
|
||||
ds = Datasette()
|
||||
await ds.invoke_startup()
|
||||
# Rest of test goes here
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ Creating a ``Datasette()`` instance like this as useful shortcut in tests, but t
|
|||
|
||||
This method registers any :ref:`plugin_hook_startup` or :ref:`plugin_hook_prepare_jinja2_environment` plugins that might themselves need to make async calls.
|
||||
|
||||
If you are using ``await datasette.client.get()`` and similar methods then you don't need to worry about this - those method calls ensure that ``.invoke_startup()`` has been called for you.
|
||||
If you are using ``await datasette.client.get()`` and similar methods then you don't need to worry about this - Datasette automatically calls ``invoke_startup()`` the first time it handles a request.
|
||||
|
||||
.. _testing_plugins_pdb:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue