Skip to content

Commit 4ec9454

Browse files
authored
Advanced Installation Guide and Test Setup Matrix Guide (#228)
* Fixed English typo * Renamed _utils_module -> _utils-module * New Doc: docs/userguide/advanced-installation.rst * New Doc: docs/userguide/setup-matrix.rst
1 parent 4e4a987 commit 4ec9454

File tree

9 files changed

+232
-5
lines changed

9 files changed

+232
-5
lines changed

docs/getting-started/first-steps.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ Let's have a quick recap over what we just learned in this section then.
537537
* - **Configurable Components**
538538
- Each default component has its ``default_`` fixtures list, which can be used to control or extend the component's functionality.
539539
* - **Setup Matrix**
540-
- The :func:`celery_setup <pytest_celery.fixtures.setup.celery_setup>` will generate a matrix of isolated environments for each test case, based on the enabled components and their configurations.
540+
- The :func:`celery_setup <pytest_celery.fixtures.setup.celery_setup>` will generate a :ref:`setup-matrix` of isolated environments for each test case, based on the enabled components and their configurations.
541541

542542
.. _built-in-components:
543543

docs/getting-started/introduction.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,7 @@ Quick Jump
257257
.. _installation:
258258

259259
.. include:: ../includes/installation.txt
260+
261+
.. tip::
262+
263+
See :ref:`advanced-installation` for more advanced installation options.

docs/includes/installation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Installing pytest-celery vendors
2323
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2424

2525
The plugin detects which vendor dependencies are installed in the test environment to configure
26-
the default configurations automatically. This means that just by installing the matching dependencies,
26+
the default configurations automatically. This means that by just installing the matching dependencies,
2727
the plugin will allow extending the default configurations, up to the supported built-in :ref:`vendors`.
2828

2929
.. warning::
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.. _advanced-installation:
2+
3+
=============================
4+
Advanced Installation Guide
5+
=============================
6+
7+
:Release: |version|
8+
:Date: |today|
9+
10+
The pytest-celery plugin uses the environment dependencies to install and configure the default setup matrix.
11+
The available dependencies are the feature flags for the available :ref:`vendors`.
12+
13+
This guide will explain how to install the plugin, how to use the dependencies feature flags and how to
14+
fit the configurations to your needs.
15+
16+
We will start by reviewing the standard installation instructions.
17+
18+
.. contents::
19+
:local:
20+
:depth: 2
21+
22+
.. include:: ../includes/installation.txt
23+
24+
Advanced Installation
25+
=====================
26+
27+
.. versionadded:: 1.0.0
28+
29+
In this section, we'll improve our understanding of the plugin installation process and how to customize it.
30+
31+
Feature Flags
32+
~~~~~~~~~~~~~
33+
34+
The installed dependencies dynamically configure which vendors are available for the plugin to use.
35+
Each vendor will provide its set of components, such as the broker, backend, and the worker, and the plugin will
36+
automatically add the matching components to the default setup matrix.
37+
38+
For example, let's assume you want to use the RabbitMQ/Redis combination.
39+
40+
1. For RabbitMQ we will need :pypi:`kombu`.
41+
2. For Redis we will need :pypi:`redis`.
42+
43+
To install the plugin with the RabbitMQ/Redis combination, you will need to install the following dependencies:
44+
45+
.. code-block:: bash
46+
47+
pip install "pytest-celery[redis]"
48+
49+
Let's break down the command:
50+
51+
- The ``pytest-celery`` is the plugin package, it will install the plugin alongside Celery and its dependencies,including **Kombu** (if not installed already).
52+
- The ``[redis]`` is the feature flag for the Redis vendor, it will install the :pypi:`redis` package and configure the plugin to use it which will add the Redis backend and Redis broker components to the default setup matrix.
53+
54+
Experimental Vendors
55+
~~~~~~~~~~~~~~~~~~~~
56+
57+
:ref:`vendors` that are in not stable, will not be added to the default setup matrix.
58+
To use the experimental vendors, you will need to configure the setup matrix manually.
59+
60+
.. tip::
61+
62+
The automatic vendors detection is implemented in :mod:`defaults.py <pytest_celery.defaults>`.
63+
64+
The ``all`` Extra
65+
~~~~~~~~~~~~~~~~~
66+
67+
The ``all`` extra is a special feature flag that will install all available vendors and their dependencies.
68+
69+
.. code-block:: bash
70+
71+
pip install "pytest-celery[all]"
72+
73+
This command will install the plugin and configure it to use all available **stable** vendors in a setup matrix for each test case
74+
that uses the :ref:`test-setup`.
75+
76+
.. warning::
77+
78+
The ``all`` extra will install **all** of the vendors dependencies, including the experimental vendor's dependencies,
79+
to allow manual configuration of the setup matrix.

docs/userguide/examples/myutils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Description
1515
===========
1616

17-
This example project shows :ref:`utils_module` to add custom APIs to the ``utils.py`` module
17+
This example project shows :ref:`utils-module` to add custom APIs to the ``utils.py`` module
1818
that is being injected into the worker container.
1919

2020
Breakdown

docs/userguide/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
:Release: |version|
88
:Date: |today|
99

10+
The following sections will enhance your understanding of the pytest-celery plugin and help you to use it effectively.
11+
It is recommended to first review the :ref:`first-steps` and :ref:`next-steps` sections to get comfortable with the basics
12+
of the plugin before diving into the advanced features.
13+
1014
.. toctree::
1115
:maxdepth: 1
1216

17+
advanced-installation
18+
setup-matrix
1319
app-conf
1420
utils-module
1521
tasks

docs/userguide/setup-matrix.rst

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
.. _setup-matrix:
2+
3+
===================
4+
Test Setup Matrix
5+
===================
6+
7+
:Release: |version|
8+
:Date: |today|
9+
10+
The plugin simplifies the setup of test environments by utilizing the
11+
`pytest fixtures mechanism <https://docs.pytest.org/en/latest/reference/fixtures.html#fixtures>`_ to configure
12+
each component of the test setup independently which allows for a high degree of flexibility in matching
13+
specific Celery architectures to each test case.
14+
15+
In this guide we'll discuss how does the setup matrix work and how to use it.
16+
17+
.. contents::
18+
:local:
19+
:depth: 2
20+
21+
What is the setup matrix?
22+
=========================
23+
24+
.. versionadded:: 1.0.0
25+
26+
The setup matrix is a combination of all of the possible Celery architectures that can be used
27+
with the available :ref:`vendors` for each test. It is automatically generated by the plugin
28+
to match the installed dependencies when using the default configuration, or it can be manually
29+
configured to set each test case separately.
30+
31+
The matrix is configured using the :ref:`default-fixtures` of each component and is available
32+
to the test case using the :ref:`test-setup`.
33+
34+
Common Setups
35+
=============
36+
37+
.. versionadded:: 1.0.0
38+
39+
The following snippets show how to use the setup matrix to configure manual setups, overriding
40+
the default configuration using the built-in :ref:`vendors`.
41+
42+
It may be used in conftest.py or in the test file itself.
43+
44+
RabbitMQ Broker and No Backend
45+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
47+
1. Use only RabbitMQ as the broker.
48+
49+
.. code-block:: python
50+
51+
@pytest.fixture
52+
def celery_broker_cluster(celery_rabbitmq_broker: RabbitMQTestBroker) -> CeleryBrokerCluster:
53+
cluster = CeleryBrokerCluster(celery_rabbitmq_broker)
54+
yield cluster
55+
cluster.teardown()
56+
57+
2. :ref:`Disable the backend <disable_backend>`.
58+
59+
.. code-block:: python
60+
61+
@pytest.fixture
62+
def celery_backend_cluster():
63+
return None
64+
65+
RabbitMQ Broker and Redis Backend
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67+
68+
1. Use only RabbitMQ as the broker.
69+
70+
.. code-block:: python
71+
72+
@pytest.fixture
73+
def celery_broker_cluster(celery_rabbitmq_broker: RabbitMQTestBroker) -> CeleryBrokerCluster:
74+
cluster = CeleryBrokerCluster(celery_rabbitmq_broker)
75+
yield cluster
76+
cluster.teardown()
77+
78+
2. Use Redis as the backend.
79+
80+
.. code-block:: python
81+
82+
@pytest.fixture
83+
def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster:
84+
cluster = CeleryBackendCluster(celery_redis_backend)
85+
yield cluster
86+
cluster.teardown()
87+
88+
Redis Broker and No Backend
89+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
90+
91+
1. Use only Redis as the broker.
92+
93+
.. code-block:: python
94+
95+
@pytest.fixture
96+
def celery_broker_cluster(celery_redis_broker: RedisTestBroker) -> CeleryBrokerCluster:
97+
cluster = CeleryBrokerCluster(celery_redis_broker)
98+
yield cluster
99+
cluster.teardown()
100+
101+
2. :ref:`Disable the backend <disable_backend>`.
102+
103+
.. code-block:: python
104+
105+
@pytest.fixture
106+
def celery_backend_cluster():
107+
return None
108+
109+
Redis Broker and Redis Backend
110+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111+
112+
1. Use only Redis as the broker.
113+
114+
.. code-block:: python
115+
116+
@pytest.fixture
117+
def celery_broker_cluster(celery_redis_broker: RedisTestBroker) -> CeleryBrokerCluster:
118+
cluster = CeleryBrokerCluster(celery_redis_broker)
119+
yield cluster
120+
cluster.teardown()
121+
122+
2. Use Redis as the backend.
123+
124+
.. code-block:: python
125+
126+
@pytest.fixture
127+
def celery_backend_cluster(celery_redis_backend: RedisTestBackend) -> CeleryBackendCluster:
128+
cluster = CeleryBackendCluster(celery_redis_backend)
129+
yield cluster
130+
cluster.teardown()

docs/userguide/utils-module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _utils_module:
1+
.. _utils-module:
22

33
==========================================
44
How to inject your own utility functions

src/pytest_celery/defaults.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""Default plugin configurations.
2+
3+
This module contains the default configurations for the pytest-celery
4+
plugin. It also contains the automatic collections that are used to
5+
parametrize the user's tests according to the components they need to
6+
run against. By default, all possible combinations are used.
7+
"""
8+
19
# flake8: noqa
210

311
from __future__ import annotations
@@ -41,7 +49,7 @@
4149
# Uses Kombu
4250
ALL_CELERY_BROKERS.append(CELERY_RABBITMQ_BROKER)
4351

44-
# Memcached is disabled by default regardless of its availability.
52+
# Memcached is disabled by default regardless of its availability due to its experimental status.
4553
if _is_vendor_installed("memcached") and False:
4654
ALL_CELERY_BACKENDS.append(CELERY_MEMCACHED_BACKEND)
4755

0 commit comments

Comments
 (0)