| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import os |
| 4 |
|
| 5 |
import pytest |
| 6 |
from pytest_celery import CeleryTestWorker, defaults |
| 7 |
from pytest_docker_tools import build, container, fxtr |
| 8 |
|
| 9 |
from celery import Celery |
| 10 |
from t.smoke.workers.dev import SmokeWorkerContainer |
| 11 |
|
| 12 |
|
| 13 |
class OtherSmokeWorkerContainer(SmokeWorkerContainer): |
| 14 |
"""Alternative worker with different name and queue, but same configurations for the rest.""" |
| 15 |
|
| 16 |
@classmethod |
| 17 |
def worker_name(cls) -> str: |
| 18 |
return "other_smoke_tests_worker" |
| 19 |
|
| 20 |
@classmethod |
| 21 |
def worker_queue(cls) -> str: |
| 22 |
return "other_smoke_tests_queue" |
| 23 |
|
| 24 |
|
| 25 |
# Build the image like the dev worker |
| 26 |
celery_other_dev_worker_image = build( |
| 27 |
path=".", |
| 28 |
dockerfile="t/smoke/workers/docker/dev", |
| 29 |
tag="t/smoke/worker:other", |
| 30 |
buildargs=OtherSmokeWorkerContainer.buildargs(), |
| 31 |
) |
| 32 |
|
| 33 |
|
| 34 |
# Define container settings like the dev worker |
| 35 |
other_dev_worker_container = container( |
| 36 |
image="{celery_other_dev_worker_image.id}", |
| 37 |
environment=fxtr("default_worker_env"), |
| 38 |
network="{default_pytest_celery_network.name}", |
| 39 |
volumes={ |
| 40 |
# Volume: Worker /app |
| 41 |
"{default_worker_volume.name}": defaults.DEFAULT_WORKER_VOLUME, |
| 42 |
# Mount: Celery source |
| 43 |
os.path.abspath(os.getcwd()): { |
| 44 |
"bind": "/celery", |
| 45 |
"mode": "rw", |
| 46 |
}, |
| 47 |
}, |
| 48 |
wrapper_class=OtherSmokeWorkerContainer, |
| 49 |
timeout=defaults.DEFAULT_WORKER_CONTAINER_TIMEOUT, |
| 50 |
command=OtherSmokeWorkerContainer.command(), |
| 51 |
) |
| 52 |
|
| 53 |
|
| 54 |
@pytest.fixture |
| 55 |
def celery_other_dev_worker( |
| 56 |
other_dev_worker_container: OtherSmokeWorkerContainer, |
| 57 |
celery_setup_app: Celery, |
| 58 |
) -> CeleryTestWorker: |
| 59 |
"""Creates a pytest-celery worker node from the worker container.""" |
| 60 |
worker = CeleryTestWorker(other_dev_worker_container, app=celery_setup_app) |
| 61 |
yield worker |
| 62 |
worker.teardown() |