Skip to content

Commit 5393045

Browse files
committed
Split up docs
1 parent e7e51aa commit 5393045

6 files changed

Lines changed: 36 additions & 22 deletions

File tree

docs/how-to-guides/custom_loop_factory.rst

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,6 @@ pytest-asyncio can run asynchronous tests with custom event loop factories by im
2121
"custom": CustomEventLoop,
2222
}
2323
24-
By default, each pytest-asyncio test is run once per configured factory. Tests managed by other async plugins are unaffected. Synchronous tests are not parametrized. The configured loop scope still determines how long each event loop instance is kept alive.
24+
See :doc:`run_test_with_specific_loop_factories` for running tests with only a subset of configured factories.
2525

26-
Factories should be callables without required parameters and should return an ``asyncio.AbstractEventLoop`` instance. The effective hook result must be a non-empty mapping of non-empty string names to callables.
27-
28-
To run a test with only a subset of configured factories, use the ``loop_factories`` argument of ``pytest.mark.asyncio``:
29-
30-
.. code-block:: python
31-
32-
import pytest
33-
34-
35-
@pytest.mark.asyncio(loop_factories=["custom"])
36-
async def test_only_with_custom_event_loop():
37-
pass
38-
39-
40-
If ``loop_factories`` contains unknown names, pytest-asyncio raises a ``pytest.UsageError`` during collection.
41-
42-
When multiple ``pytest_asyncio_loop_factories`` implementations are present, pytest-asyncio uses the first non-``None`` result in pytest's hook dispatch order.
43-
44-
.. note::
45-
46-
When the hook is defined, async tests are parametrized via ``pytest.metafunc.parametrize``, and mapping keys are used as test IDs. For example, a test ``test_example`` with an event loop factory key ``foo`` will appear as ``test_example[foo]`` in test output.
26+
See :doc:`../reference/hooks` and :doc:`../reference/markers/index` for the hook and marker reference.

docs/how-to-guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ How-To Guides
1111
change_default_fixture_loop
1212
change_default_test_loop
1313
custom_loop_factory
14+
run_test_with_specific_loop_factories
1415
run_class_tests_in_same_loop
1516
run_module_tests_in_same_loop
1617
run_package_tests_in_same_loop
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=========================================================
2+
How to run a test with specific event loop factories only
3+
=========================================================
4+
5+
To run a test with only a subset of configured factories, use the ``loop_factories`` argument of ``pytest.mark.asyncio``:
6+
7+
.. code-block:: python
8+
9+
import pytest
10+
11+
12+
@pytest.mark.asyncio(loop_factories=["custom"])
13+
async def test_only_with_custom_event_loop():
14+
pass

docs/reference/hooks.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=====
2+
Hooks
3+
=====
4+
5+
``pytest_asyncio_loop_factories``
6+
=================================
7+
8+
This hook returns a mapping from factory name strings to event loop factory callables for the current test item.
9+
10+
By default, each pytest-asyncio test is run once per configured factory. Tests managed by other async plugins are unaffected. Synchronous tests are not parametrized. The configured loop scope still determines how long each event loop instance is kept alive.
11+
12+
Factories should be callables without required parameters and should return an ``asyncio.AbstractEventLoop`` instance. The effective hook result must be a non-empty mapping of non-empty string names to callables.
13+
14+
When multiple ``pytest_asyncio_loop_factories`` implementations are present, pytest-asyncio uses the first non-``None`` result in pytest's hook dispatch order.
15+
16+
When the hook is defined, async tests are parametrized via ``pytest.metafunc.parametrize``, and mapping keys are used as test IDs. For example, a test ``test_example`` with an event loop factory key ``foo`` will appear as ``test_example[foo]`` in test output.

docs/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Reference
88
configuration
99
fixtures/index
1010
functions
11+
hooks
1112
markers/index
1213
decorators/index
1314
changelog

docs/reference/markers/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Subpackages do not share the loop with their parent package.
3636

3737
Tests marked with *session* scope share the same event loop, even if the tests exist in different packages.
3838

39+
The ``pytest.mark.asyncio`` marker also accepts a ``loop_factories`` keyword argument to select a subset of configured event loop factories for a test. If ``loop_factories`` contains unknown names, pytest-asyncio raises a ``pytest.UsageError`` during collection.
40+
3941
.. |auto mode| replace:: *auto mode*
4042
.. _auto mode: ../../concepts.html#auto-mode
4143
.. |pytestmark| replace:: ``pytestmark``

0 commit comments

Comments
 (0)