Skip to content

Commit 0a48269

Browse files
committed
feat(docs): add tabs and group tabs to improve documentation examples
1 parent d88c61a commit 0a48269

File tree

5 files changed

+87
-49
lines changed

5 files changed

+87
-49
lines changed

docs/concepts.rst

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,50 @@ Assigning neighboring tests to different event loop scopes is discouraged as it
4747
Test discovery modes
4848
====================
4949

50-
Pytest-asyncio provides two modes for test discovery, *strict* and *auto*. This can be set through Pytest's ``--asyncio-mode`` command line flag, or through the configuration file:
50+
Pytest-asyncio provides two modes for test discovery, *strict* and *auto*.
51+
This can be set through Pytest's ``--asyncio-mode`` command line flag,
52+
or through the configuration file.
5153

52-
.. code-block:: toml
54+
.. tabs::
5355

54-
[tool.pytest.ini_options]
55-
asyncio_mode = "auto" # or "strict"
56+
.. group-tab:: Strict mode
5657

57-
Strict mode
58-
-----------
58+
.. code-block:: toml
5959
60-
In strict mode pytest-asyncio will only run tests that have the *asyncio* marker and will only evaluate async fixtures decorated with ``@pytest_asyncio.fixture``. Test functions and fixtures without these markers and decorators will not be handled by pytest-asyncio.
60+
[tool.pytest.ini_options]
61+
asyncio_mode = "strict"
6162
62-
This mode is intended for projects that want so support multiple asynchronous programming libraries as it allows pytest-asyncio to coexist with other async testing plugins in the same codebase.
63+
In strict mode pytest-asyncio will only run tests that have the *asyncio* marker
64+
and will only evaluate async fixtures decorated with ``@pytest_asyncio.fixture``.
65+
Test functions and fixtures without these markers and decorators will not be
66+
handled by pytest-asyncio.
6367

64-
Pytest automatically enables installed plugins. As a result pytest plugins need to coexist peacefully in their default configuration. This is why strict mode is the default mode.
68+
This mode is intended for projects that want to support multiple asynchronous
69+
programming libraries as it allows pytest-asyncio to coexist with other async
70+
testing plugins in the same codebase.
6571

66-
Auto mode
67-
---------
72+
Pytest automatically enables installed plugins. As a result pytest plugins
73+
need to coexist peacefully in their default configuration. This is why strict
74+
mode is the default mode.
6875

69-
In *auto* mode pytest-asyncio automatically adds the *asyncio* marker to all asynchronous test functions. It will also take ownership of all async fixtures, regardless of whether they are decorated with ``@pytest.fixture`` or ``@pytest_asyncio.fixture``.
76+
.. group-tab:: Auto mode
7077

71-
This mode is intended for projects that use *asyncio* as their only asynchronous programming library. Auto mode makes for the simplest test and fixture configuration and is the recommended default.
78+
.. code-block:: toml
7279
73-
If you intend to support multiple asynchronous programming libraries, e.g. *asyncio* and *trio*, strict mode will be the preferred option.
80+
[tool.pytest.ini_options]
81+
asyncio_mode = "auto"
82+
83+
In *auto* mode pytest-asyncio automatically adds the *asyncio* marker to all
84+
asynchronous test functions. It will also take ownership of all async fixtures,
85+
regardless of whether they are decorated with ``@pytest.fixture`` or
86+
``@pytest_asyncio.fixture``.
87+
88+
This mode is intended for projects that use *asyncio* as their only asynchronous
89+
programming library. Auto mode makes for the simplest test and fixture
90+
configuration and is the recommended default.
91+
92+
If you intend to support multiple asynchronous programming libraries,
93+
e.g. *asyncio* and *trio*, strict mode will be the preferred option.
7494

7595
.. _concepts/concurrent_execution:
7696

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# -- General configuration ---------------------------------------------------
1717
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1818

19-
extensions = []
19+
extensions = ["sphinx_tabs.tabs"]
2020

2121
templates_path = ["_templates"]
2222
exclude_patterns = []

docs/how-to-guides/change_default_fixture_loop.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ How to change the default event loop scope of all fixtures
33
==========================================================
44
The :ref:`configuration/asyncio_default_fixture_loop_scope` configuration option sets the default event loop scope for asynchronous fixtures. The following code snippets configure all fixtures to run in a session-scoped loop by default:
55

6-
.. code-block:: ini
7-
:caption: pytest.ini
6+
.. tabs::
87

9-
[pytest]
10-
asyncio_default_fixture_loop_scope = session
8+
.. tab:: pytest.ini
119

12-
.. code-block:: toml
13-
:caption: pyproject.toml
10+
.. code-block:: ini
1411
15-
[tool.pytest.ini_options]
16-
asyncio_default_fixture_loop_scope = "session"
12+
[pytest]
13+
asyncio_default_fixture_loop_scope = session
1714
18-
.. code-block:: ini
19-
:caption: setup.cfg
15+
.. tab:: pyproject.toml
2016

21-
[tool:pytest]
22-
asyncio_default_fixture_loop_scope = session
17+
.. code-block:: toml
18+
19+
[tool.pytest.ini_options]
20+
asyncio_default_fixture_loop_scope = "session"
21+
22+
.. tab:: setup.cfg
23+
24+
.. code-block:: ini
25+
26+
[tool:pytest]
27+
asyncio_default_fixture_loop_scope = session
2328
2429
Please refer to :ref:`configuration/asyncio_default_fixture_loop_scope` for other valid scopes.

docs/how-to-guides/change_default_test_loop.rst

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@ How to change the default event loop scope of all tests
33
=======================================================
44
The :ref:`configuration/asyncio_default_test_loop_scope` configuration option sets the default event loop scope for asynchronous tests. The following code snippets configure all tests to run in a session-scoped loop by default:
55

6-
.. code-block:: ini
7-
:caption: pytest.ini
6+
.. tabs::
87

9-
[pytest]
10-
asyncio_default_test_loop_scope = session
8+
.. tab:: pytest.ini
119

12-
.. code-block:: toml
13-
:caption: pyproject.toml
10+
.. code-block:: ini
1411
15-
[tool.pytest.ini_options]
16-
asyncio_default_test_loop_scope = "session"
12+
[pytest]
13+
asyncio_default_test_loop_scope = session
1714
18-
.. code-block:: ini
19-
:caption: setup.cfg
15+
.. tab:: pyproject.toml
2016

21-
[tool:pytest]
22-
asyncio_default_test_loop_scope = session
17+
.. code-block:: toml
2318
24-
Please refer to :ref:`configuration/asyncio_default_test_loop_scope` for other valid scopes.
19+
[tool.pytest.ini_options]
20+
asyncio_default_test_loop_scope = "session"
21+
22+
.. tab:: setup.cfg
23+
24+
.. code-block:: ini
25+
26+
[tool:pytest]
27+
asyncio_default_test_loop_scope = session
28+
29+
Please refer to :ref:`configuration/asyncio_default_test_loop_scope`
30+
for other valid scopes.

docs/reference/markers/index.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,32 @@ Markers
99
A coroutine or async generator with this marker is treated as a test function by pytest.
1010
The marked function is executed as an asyncio task in the event loop provided by pytest-asyncio.
1111

12-
.. include:: function_scoped_loop_strict_mode_example.py
13-
:code: python
12+
Multiple async tests in a single class or module can be marked in different ways:
1413

15-
Multiple async tests in a single class or module can be marked using |pytestmark|_.
14+
.. tabs::
1615

17-
.. include:: function_scoped_loop_pytestmark_strict_mode_example.py
18-
:code: python
16+
.. tab:: decorator
17+
18+
.. include:: function_scoped_loop_strict_mode_example.py
19+
:code: python
20+
21+
.. tab:: pytestmark
22+
23+
.. include:: function_scoped_loop_pytestmark_strict_mode_example.py
24+
:code: python
1925

2026
The ``pytest.mark.asyncio`` marker can be omitted entirely in |auto mode|_ where the *asyncio* marker is added automatically to *async* test functions.
2127

22-
By default, each test runs in it's own asyncio event loop.
28+
By default, each test runs in its own asyncio event loop.
2329
Multiple tests can share the same event loop by providing a *loop_scope* keyword argument to the *asyncio* mark.
24-
The supported scopes are *function,* *class,* and *module,* *package,* and *session*.
25-
The following code example provides a shared event loop for all tests in `TestClassScopedLoop`:
30+
The supported scopes are *function*, *class*, *module*, *package*, and *session*.
31+
32+
The following code example provides a shared event loop for all tests in ``TestClassScopedLoop``:
2633

2734
.. include:: class_scoped_loop_strict_mode_example.py
2835
:code: python
2936

30-
Similar to class-scoped event loops, a module-scoped loop is provided when setting mark's scope to *module:*
37+
Similar to class-scoped event loops, a module-scoped loop is provided when setting mark's scope to *module*:
3138

3239
.. include:: module_scoped_loop_strict_mode_example.py
3340
:code: python

0 commit comments

Comments
 (0)