Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ on:
permissions:
contents: read # to fetch code (actions/checkout)

env:
PYTEST_CELERY_PKG: "pytest-celery@git+https://github.com/${{ github.event.pull_request.head.repo.full_name || github.repository }}.git@${{ github.event.pull_request.head.sha || github.sha }}"

jobs:
celery_bug_report:
runs-on: ${{ matrix.os }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ on:
permissions:
contents: read # to fetch code (actions/checkout)

env:
PYTEST_CELERY_PKG: "pytest-celery@git+https://github.com/${{ github.event.pull_request.head.repo.full_name || github.repository }}.git@${{ github.event.pull_request.head.sha || github.sha }}"

jobs:
Unit:
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions src/pytest_celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
from pytest_celery.vendors.worker.fixtures import default_worker_env
from pytest_celery.vendors.worker.fixtures import default_worker_initial_content
from pytest_celery.vendors.worker.fixtures import default_worker_ports
from pytest_celery.vendors.worker.fixtures import default_worker_pytest_celery_pkg
from pytest_celery.vendors.worker.fixtures import default_worker_signals
from pytest_celery.vendors.worker.fixtures import default_worker_tasks
from pytest_celery.vendors.worker.fixtures import default_worker_utils_module
Expand Down
3 changes: 2 additions & 1 deletion src/pytest_celery/vendors/worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ARG CELERY_VERSION=""
ARG CELERY_LOG_LEVEL=INFO
ARG CELERY_WORKER_NAME=celery_test_worker
ARG CELERY_WORKER_QUEUE=celery
ARG PYTEST_CELERY_PKG="pytest-celery"
ENV WORKER_VERSION=$CELERY_VERSION
ENV LOG_LEVEL=$CELERY_LOG_LEVEL
ENV WORKER_NAME=$CELERY_WORKER_NAME
Expand All @@ -40,7 +41,7 @@ EXPOSE 5678
RUN pip install --no-cache-dir --upgrade \
pip \
celery[redis,pymemcache,gevent,sqs]${WORKER_VERSION:+==$WORKER_VERSION} \
pytest-celery
"${PYTEST_CELERY_PKG}"

# The workdir must be /app
WORKDIR /app
Expand Down
11 changes: 11 additions & 0 deletions src/pytest_celery/vendors/worker/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_LOG_LEVEL
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_NAME
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_PORTS
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_PYTEST_CELERY_PKG
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_QUEUE
from pytest_celery.vendors.worker.defaults import DEFAULT_WORKER_VERSION
from pytest_celery.vendors.worker.volume import WorkerInitialContent
Expand Down Expand Up @@ -140,6 +141,15 @@ def signals_modules(cls) -> set:
"""
return set()

@classmethod
def pytest_celery_pkg(cls) -> str:
"""The pytest-celery package to install in the worker container.

Returns:
str: pip install spec for pytest-celery.
"""
return DEFAULT_WORKER_PYTEST_CELERY_PKG

@classmethod
def buildargs(cls) -> dict:
"""Build arguments for the built-in worker image."""
Expand All @@ -148,6 +158,7 @@ def buildargs(cls) -> dict:
"CELERY_LOG_LEVEL": cls.log_level(),
"CELERY_WORKER_NAME": cls.worker_name(),
"CELERY_WORKER_QUEUE": cls.worker_queue(),
"PYTEST_CELERY_PKG": cls.pytest_celery_pkg(),
}

@classmethod
Expand Down
1 change: 1 addition & 0 deletions src/pytest_celery/vendors/worker/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
DEFAULT_WORKER_QUEUE = WORKER_QUEUE
DEFAULT_WORKER_CONTAINER_TIMEOUT = 60
DEFAULT_WORKER_VOLUME = WORKER_VOLUME
DEFAULT_WORKER_PYTEST_CELERY_PKG = os.environ.get("PYTEST_CELERY_PKG", "pytest-celery")
14 changes: 14 additions & 0 deletions src/pytest_celery/vendors/worker/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def default_worker_container_session_cls() -> type[CeleryWorkerContainer]:
"CELERY_LOG_LEVEL": fxtr("default_worker_celery_log_level"),
"CELERY_WORKER_NAME": fxtr("default_worker_celery_worker_name"),
"CELERY_WORKER_QUEUE": fxtr("default_worker_celery_worker_queue"),
"PYTEST_CELERY_PKG": fxtr("default_worker_pytest_celery_pkg"),
},
)

Expand Down Expand Up @@ -163,6 +164,19 @@ def default_worker_celery_worker_queue(default_worker_container_session_cls: typ
return default_worker_container_session_cls.worker_queue()


@pytest.fixture(scope="session")
def default_worker_pytest_celery_pkg(default_worker_container_session_cls: type[CeleryWorkerContainer]) -> str:
"""The pytest-celery package to install in the worker container.

Args:
default_worker_container_session_cls (type[CeleryWorkerContainer]): See also: :ref:`vendor-class`.

Returns:
str: pip install spec for pytest-celery.
"""
return default_worker_container_session_cls.pytest_celery_pkg()


@pytest.fixture
def default_worker_command(default_worker_container_cls: type[CeleryWorkerContainer]) -> list[str]:
"""Command to run the container.
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/vendors/test_worker/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pytest_celery import DEFAULT_WORKER_ENV
from pytest_celery import DEFAULT_WORKER_LOG_LEVEL
from pytest_celery import DEFAULT_WORKER_NAME
from pytest_celery import DEFAULT_WORKER_PYTEST_CELERY_PKG
from pytest_celery import DEFAULT_WORKER_QUEUE
from pytest_celery import DEFAULT_WORKER_VERSION
from pytest_celery import CeleryBackendCluster
Expand Down Expand Up @@ -46,6 +47,7 @@ def test_buildargs(self):
"CELERY_LOG_LEVEL": DEFAULT_WORKER_LOG_LEVEL,
"CELERY_WORKER_NAME": DEFAULT_WORKER_NAME,
"CELERY_WORKER_QUEUE": DEFAULT_WORKER_QUEUE,
"PYTEST_CELERY_PKG": DEFAULT_WORKER_PYTEST_CELERY_PKG,
}

class test_celery_worker_container_env:
Expand Down
Loading