This document is for pytest_celery's development version, which can be significantly different from previous releases. Get the stable docs here: 1.1.
pytest_celery.vendors.worker package¶
Subpackages¶
Submodules¶
pytest_celery.vendors.worker.container module¶
The pytest-celery plugin provides a set of built-in components called Vendors.
This module is part of the Built-in Celery Worker vendor.
- class pytest_celery.vendors.worker.container.CeleryWorkerContainer(container)[source]¶
Bases:
CeleryTestContainer
This is the base class for all Celery worker containers. It is preconfigured for a built-in Celery worker image and should be customized for your own worker image.
The purpose of this class is manipulating the container volume and configurations to warm up the worker container according to the test case requirements.
- Responsibility Scope:
Prepare the worker container with the required filesystem, configurations and dependencies of your project.
- classmethod app_module() ModuleType [source]¶
A preconfigured module that contains the Celery app instance.
The module is manipulated at runtime to inject the required configurations from the test case.
- classmethod command(*args: str, debugpy: bool = False, wait_for_client: bool = True, **kwargs: dict) list[str] [source]¶
Override the CMD instruction in the Dockerfile.
This method should be overridden in derived classes to provide the specific command and its arguments required to start the container.
- Parameters:
- Raises:
NotImplementedError – Rely on the Dockerfile if not set otherwise by default.
- Returns:
- A list containing the command to run in the container as
the first element, followed by the command-line arguments.
- Return type:
- classmethod initial_content(worker_tasks: set | None = None, worker_signals: set | None = None, worker_app: Celery | None = None, app_module: ModuleType | None = None, utils_module: ModuleType | None = None) dict [source]¶
Defines the initial content of the worker container.
See more: pytest_docker_tools.volume()
- Parameters:
worker_tasks (set | None, optional) – Set of tasks modules. Defaults to None.
worker_signals (set | None, optional) – Set of signals handlers modules. Defaults to None.
worker_app (Celery | None, optional) – Celery app instance. Defaults to None.
app_module (ModuleType | None, optional) – app module. Defaults to None.
utils_module (ModuleType | None, optional) – utils module. Defaults to None.
- Returns:
Custom volume content for the worker container.
- Return type:
- classmethod initial_env(celery_worker_cluster_config: dict, initial: dict | None = None) dict [source]¶
Defines the environment variables for the worker container.
See more: pytest_docker_tools.container()
- property ready_prompt: str¶
A log string that indicates the container has finished starting up and is ready to use.
- Returns:
A string to wait for or None for no wait. Defaults to None.
- Return type:
str | None
- classmethod signals_modules() set [source]¶
Signals handlers modules.
This is an optional feature that can be used to inject signals handlers that needs to in the context of the worker container.
- classmethod utils_module() ModuleType [source]¶
A utility helper module for running python code in the worker container context.
pytest_celery.vendors.worker.defaults module¶
The pytest-celery plugin provides a set of built-in components called Vendors.
This module is part of the Built-in Celery Worker vendor.
pytest_celery.vendors.worker.fixtures module¶
The pytest-celery plugin provides a set of built-in components called Vendors.
This module is part of the Built-in Celery Worker vendor.
- pytest_celery.vendors.worker.fixtures.celery_setup_worker(default_worker_cls: type[CeleryTestWorker], default_worker_container: CeleryWorkerContainer, default_worker_app: Celery) CeleryTestWorker [source]¶
Creates a CeleryTestWorker instance. Responsible for tearing down the node.
- Parameters:
default_worker_cls (type[CeleryTestWorker]) – Interface class.
default_worker_container (CeleryWorkerContainer) – Instantiated CeleryWorkerContainer.
default_worker_app (Celery) – Celery app instance.
- pytest_celery.vendors.worker.fixtures.default_worker_app(celery_setup_app: Celery) Celery [source]¶
Celery app instance for this worker.
- Parameters:
celery_setup_app (Celery) – See also: Vendor Class.
- Returns:
Celery app instance.
- Return type:
Celery
- pytest_celery.vendors.worker.fixtures.default_worker_app_module(default_worker_container_cls: type[CeleryWorkerContainer]) ModuleType [source]¶
App module for this worker.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
App module.
- Return type:
ModuleType
- pytest_celery.vendors.worker.fixtures.default_worker_celery_log_level(default_worker_container_session_cls: type[CeleryWorkerContainer]) str [source]¶
Log level for this worker.
- Parameters:
default_worker_container_session_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Log level.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_celery_version(default_worker_container_session_cls: type[CeleryWorkerContainer]) str [source]¶
Celery version for this worker.
- Parameters:
default_worker_container_session_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Celery version.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_celery_worker_name(default_worker_container_session_cls: type[CeleryWorkerContainer]) str [source]¶
Name of the worker.
- Parameters:
default_worker_container_session_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Worker name.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_celery_worker_queue(default_worker_container_session_cls: type[CeleryWorkerContainer]) str [source]¶
Worker queue for this worker.
- Parameters:
default_worker_container_session_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Worker queue.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_cls() type[CeleryTestWorker] [source]¶
Default worker class. Override to apply custom configuration globally.
See also: Vendor Class.
- Returns:
API for managing the vendor’s node.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_command(default_worker_container_cls: type[CeleryWorkerContainer]) list[str] [source]¶
Command to run the container.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Docker CMD instruction.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_container_cls() type[CeleryWorkerContainer] [source]¶
Default worker container class. Override to apply custom configuration globally.
See also: Vendor Class.
- Returns:
API for managing the vendor’s container.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_container_session_cls() type[CeleryWorkerContainer] [source]¶
Default worker container session class. Override to apply custom configuration globally.
See also: Vendor Class.
- Returns:
API for managing the vendor’s container.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_env(default_worker_container_cls: type[CeleryWorkerContainer], celery_worker_cluster_config: dict) dict [source]¶
Environment variables for this worker.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
celery_worker_cluster_config (dict) – Broker & Backend clusters configuration.
- Returns:
Items to pass to the container’s environment.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_initial_content(default_worker_container_cls: type[CeleryWorkerContainer], default_worker_app_module: ModuleType, default_worker_utils_module: ModuleType, default_worker_tasks: set, default_worker_signals: set, default_worker_app: Celery) dict [source]¶
Initial content for this worker’s volume.
This is applied on a worker container when using the following volume configuration:
default_worker_container = container( ... volumes={"{default_worker_volume.name}": DEFAULT_WORKER_VOLUME}, ... )
Note
More volumes may be added additionally.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
default_worker_app_module (ModuleType) – App module to inject.
default_worker_utils_module (ModuleType) – Utils module to inject.
default_worker_tasks (set) – Tasks modules to inject.
default_worker_signals (set) – Signals modules to inject.
default_worker_app (Celery) – Celery app to initialize the worker with.
- Returns:
Initial volume content (dict of files).
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_ports(default_worker_container_cls: type[CeleryWorkerContainer]) dict | None [source]¶
Port bindings for this vendor.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Port bindings.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_signals(default_worker_container_cls: type[CeleryWorkerContainer]) set [source]¶
Signals modules set for this worker.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Signals modules.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_tasks(default_worker_container_cls: type[CeleryWorkerContainer]) set [source]¶
Tasks modules set for this worker.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Tasks modules.
- Return type:
- pytest_celery.vendors.worker.fixtures.default_worker_utils_module(default_worker_container_cls: type[CeleryWorkerContainer]) ModuleType [source]¶
Utils module for this worker.
- Parameters:
default_worker_container_cls (type[CeleryWorkerContainer]) – See also: Vendor Class.
- Returns:
Utils module.
- Return type:
ModuleType
pytest_celery.vendors.worker.tasks module¶
The pytest-celery plugin provides a set of built-in components called Vendors.
This module is part of the Built-in Celery Worker vendor.
- (task)pytest_celery.vendors.worker.tasks.add(x: 'int | float', y: 'int | float', z: 'int | float | None' = None) 'int | float' [source]¶
Pytest-celery internal task.
This task adds two or three numbers together.
- (task)pytest_celery.vendors.worker.tasks.add_replaced(x: 'int | float', y: 'int | float', z: 'int | float | None' = None, *, queue: 'str | None' = None) 'None' [source]¶
Pytest-celery internal task.
This task replaces itself with the add task for the given arguments.
- (task)pytest_celery.vendors.worker.tasks.fail(*args: 'tuple') 'None' [source]¶
Pytest-celery internal task.
This task raises a RuntimeError with the given arguments.
- Parameters:
*args (tuple) – Arguments to pass to the RuntimeError.
- Raises:
RuntimeError – Always raises a RuntimeError.
- (task)pytest_celery.vendors.worker.tasks.identity(x: 'Any') 'Any' [source]¶
Pytest-celery internal task.
This task returns the input as is.
- Parameters:
x (Any) – Any value.
- Returns:
The input value.
- Return type:
Any
- (task)pytest_celery.vendors.worker.tasks.noop(*args: 'tuple', **kwargs: 'dict') 'None' [source]¶
Pytest-celery internal task.
This is a no-op task that does nothing.
- Returns:
Always returns None.
- Return type:
None
- (task)pytest_celery.vendors.worker.tasks.ping() 'str' [source]¶
Pytest-celery internal task.
Used to check if the worker is up and running.
- Returns:
Always returns “pong”.
- Return type:
pytest_celery.vendors.worker.volume module¶
The pytest-celery plugin provides a set of built-in components called Vendors.
This module is part of the Built-in Celery Worker vendor.
- class pytest_celery.vendors.worker.volume.WorkerInitialContent(app_module: ModuleType | None = None, utils_module: ModuleType | None = None)[source]¶
Bases:
object
This class is responsible for generating the initial content for the worker container volume.
- Responsibility Scope:
Prepare the worker container with the required filesystem, configurations and dependencies for your project.
- class Parser[source]¶
Bases:
object
Parser for the initial content of the worker container.
- imports_src(modules: set[ModuleType]) dict [source]¶
Parse the given modules and return a dict with the source code of the modules.
- add_modules(name: str, modules: set[ModuleType]) None [source]¶
Adds a set of modules to the initial content.
- generate() dict [source]¶
Generates the initial content for the worker container.
- Returns:
Initial content volume for the worker container.
- Return type:
- set_app_module(app_module: ModuleType | None = None) None [source]¶
Injects an app module into the initial content.
- set_app_name(name: str | None = None) None [source]¶
Sets the Celery app name.
- Parameters:
name (str | None, optional) – The app name. Defaults to None.
- set_config_from_object(app: Celery | None = None) None [source]¶
Sets the Celery app configuration from the given app.
- Parameters:
app (Celery | None, optional) – Celery app with possibly changed config. Defaults to None.
- set_utils_module(utils_module: ModuleType | None = None) None [source]¶
Injects a utils module into the initial content.
Module contents¶
The pytest-celery plugin provides a set of built-in components called Vendors.
This module is part of the Built-in Celery Worker vendor.