Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Mar 3, 2024
1 parent e85bf82 commit c8cf855
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build:
# Tell poetry to not use a virtual environment
- poetry config virtualenvs.create false
post_install:
- poetry install --with docs
- poetry install -E "all" --with docs

# Build documentation in the "docs/" directory with Sphinx
sphinx:
Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ What do I need?

- Python ❨3.8, 3.9, 3.10, 3.11, 3.12❩

Celery is required and may be installed separately or automatically using the ``all`` extra.
When used with the ``all`` extra, pytest-celery will install the latest version of Celery
and all of the plugin vendors dependencies.

The pytest-celery plugin is Celery-agnostic, and should work with virtually any version of Celery.

.. warning::
Expand Down
9 changes: 7 additions & 2 deletions docs/includes/installation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ To install using :command:`pip`:

$ pip install -U pytest-celery

The :pypi:`celery` package will be installed by default with the ``redis`` and ``pymemcache``
`extras <https://docs.celeryq.dev/en/stable/getting-started/introduction.html#transports-and-backends>`_.
Using the ``all`` extra:

.. code-block:: console

$ pip install -U "pytest-celery[all]"

This will install the package with all optional dependencies.

With git
~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions examples/django/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ sqlalchemy>=1.2.18
django>=2.2.1
pytest-django>=4.7.0
pytest-xdist>=3.5.0
pytest-celery~=1.0.0b
celery[redis,pymemcache]>=5.0.0
pytest-celery[all]@git+https://github.com/celery/pytest-celery.git@bugfix
3 changes: 1 addition & 2 deletions examples/myutils/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pytest>=7.4.4
pytest-xdist>=3.5.0
pytest-celery~=1.0.0b
celery[redis,pymemcache]>=5.0.0
pytest-celery[all]@git+https://github.com/celery/pytest-celery.git@bugfix
3 changes: 1 addition & 2 deletions examples/myworker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pytest>=7.4.4
pytest-xdist>=3.5.0
pytest-celery~=1.0.0b
celery[redis,pymemcache]>=5.0.0
pytest-celery[all]@git+https://github.com/celery/pytest-celery.git@bugfix
3 changes: 1 addition & 2 deletions examples/rabbitmq_management/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pytest>=7.4.4
pytest-xdist>=3.5.0
pytest-celery~=1.0.0b
celery[redis,pymemcache]>=5.0.0
pytest-celery[all]@git+https://github.com/celery/pytest-celery.git@bugfix
3 changes: 1 addition & 2 deletions examples/range/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest>=7.4.4
pytest-xdist>=3.5.0
pytest-subtests>=0.11.0
pytest-celery~=1.0.0b
celery[redis,pymemcache]>=5.0.0
pytest-celery[all]@git+https://github.com/celery/pytest-celery.git@bugfix
230 changes: 125 additions & 105 deletions poetry.lock

Large diffs are not rendered by default.

65 changes: 37 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,78 +72,87 @@ search = ':Version: {current_version}'
replace = ':Version: {new_version}'

[tool.poetry.dependencies]
celery = { version = "^5.0.0", extras = ["redis", "pymemcache"] }
python = ">= 3.8,<4.0"
retry = "^0.9.2"
pytest-docker-tools = "^3.1.3"
celery = { version = "*", optional = true }
redis = { version = "*", optional = true }
python-memcached = { version = "*", optional = true }
python = ">=3.8,<4.0"
retry = ">=0.9.2"
pytest-docker-tools = ">=3.1.3"
docker = "^7.0.0"
psutil = "^5.9.7"
setuptools = "^69.1.0"
psutil = ">=5.9.7"
setuptools = ">=69.1.0"

[tool.poetry.extras]
all = ["celery", "redis", "python-memcached"]
celery = ["celery"]
redis = ["redis"]
memcached = ["python-memcached"]

[tool.poetry.group.dev]

[tool.poetry.group.dev.dependencies]
poetry-bumpversion = "^0.3.2"
poetry-bumpversion = ">=0.3.2"
black = "*"
toml-sort = "^0.23.1"
toml-sort = ">=0.23.1"
autoflake = [
{ version = "^1.7.0", python = "<3.8.1" },
{ version = "^2.0.0", python = ">=3.8.1,<4.0" },
{ version = ">=2.0.0", python = ">=3.8.1,<4.0" },
]
isort = [
{ version = "^5.11.0", python = "<3.8.0" },
{ version = "^5.12.0", python = ">=3.8.0,<4.0" },
{ version = ">=5.12.0", python = ">=3.8.0,<4.0" },
]
flake8 = [
{ version = "^5.0.0", python = "<3.8.1" },
{ version = "^6.0.0", python = ">=3.8.1,<4.0" },
{ version = ">=6.0.0", python = ">=3.8.1,<4.0" },
]
pre-commit = [
{ version = "^2.21.0", python = "<3.8.0" },
{ version = "^3.1.0", python = ">=3.8.0,<4.0" },
{ version = ">=3.6.0", python = ">=3.9.0,<4.0" },
]
mypy = "^1.0.1"
types-redis = "^4.6.0.20240218"
cleanpy = "^0.4.0"
mypy = ">=1.0.1"
types-redis = ">=4.6.0.20240218"
cleanpy = ">=0.4.0"

[tool.poetry.group.test]
optional = true

[tool.poetry.group.test.dependencies]
pytest = "^8.0.1"
coverage = "^7.4.2"
pytest-sugar = { version = "^1.0.0", python = ">=3.8,<4.0" }
pytest-cov = "^4.0.0"
pytest-xdist = "^3.1.0"
pytest-subtests = "^0.11.0"
pytest-rerunfailures = "^13.0"
coverage = ">=7.4.2"
pytest-sugar = { version = ">=1.0.0", python = ">=3.8,<4.0" }
pytest-cov = ">=4.0.0"
pytest-xdist = ">=3.1.0"
pytest-subtests = ">=0.11.0"
pytest-rerunfailures = ">=13.0.0"

[tool.poetry.group.ci]
optional = true

[tool.poetry.group.ci.dependencies]
tox = [
{ version = "^3.0.0", python = "<3.8.1" },
{ version = "^4.0.0", python = ">=3.8.1,<4.0" },
{ version = ">=4.0.0", python = ">=3.8.1,<4.0" },
]
tox-gh-actions = [
{ version = "^2.0.0", python = "<3.8.1" },
{ version = "^3.0.0", python = ">=3.8.1,<4.0" },
{ version = ">=3.0.0", python = ">=3.8.1,<4.0" },
]

[tool.poetry.group.docs]
optional = true

[tool.poetry.group.docs.dependencies]
sphinx_celery = "^2.1.3"
sphinx_celery = ">=2.1.3"
Sphinx = [
{ version = "^7.1.0", python = "<3.9" },
{ version = "^7.0.0", python = ">=3.9,<4.0" },
{ version = ">=7.0.0", python = ">=3.9,<4.0" },
]
sphinx-testing = "^1.0.1"
sphinx-click = "^5.1.0"
sphinx-autobuild = "^2021.3.14"
sphinxcontrib-mermaid = "^0.9.2"
sphinx-testing = ">=1.0.1"
sphinx-click = ">=5.1.0"
sphinx-autobuild = ">=2021.3.14"
sphinxcontrib-mermaid = ">=0.9.2"

[tool.poetry.plugins.pytest11]
celery = "pytest_celery.plugin"
Expand Down
123 changes: 96 additions & 27 deletions src/pytest_celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,103 @@
import re
from collections import namedtuple

from pytest_celery.api.backend import *
from pytest_celery.api.base import *
from pytest_celery.api.broker import *
from pytest_celery.api.container import *
from pytest_celery.api.setup import *
from pytest_celery.api.worker import *
from pytest_celery.api.backend import CeleryBackendCluster
from pytest_celery.api.backend import CeleryTestBackend
from pytest_celery.api.base import CeleryTestCluster
from pytest_celery.api.base import CeleryTestNode
from pytest_celery.api.broker import CeleryBrokerCluster
from pytest_celery.api.broker import CeleryTestBroker
from pytest_celery.api.container import CeleryTestContainer
from pytest_celery.api.setup import CeleryTestSetup
from pytest_celery.api.worker import CeleryTestWorker
from pytest_celery.api.worker import CeleryWorkerCluster

Check warning on line 25 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L16-L25

Added lines #L16 - L25 were not covered by tests
from pytest_celery.defaults import *
from pytest_celery.fixtures.backend import *
from pytest_celery.fixtures.broker import *
from pytest_celery.fixtures.setup import *
from pytest_celery.fixtures.worker import *
from pytest_celery.vendors.memcached.api import *
from pytest_celery.vendors.memcached.container import *
from pytest_celery.vendors.memcached.fixtures import *
from pytest_celery.vendors.rabbitmq.api import *
from pytest_celery.vendors.rabbitmq.container import *
from pytest_celery.vendors.rabbitmq.fixtures import *
from pytest_celery.vendors.redis.backend.api import *
from pytest_celery.vendors.redis.backend.fixtures import *
from pytest_celery.vendors.redis.broker.api import *
from pytest_celery.vendors.redis.broker.fixtures import *
from pytest_celery.vendors.redis.container import *
from pytest_celery.vendors.worker.container import *
from pytest_celery.vendors.worker.content import app
from pytest_celery.vendors.worker.content import utils
from pytest_celery.vendors.worker.fixtures import *
from pytest_celery.vendors.worker.tasks import *
from pytest_celery.vendors.worker.volume import *
from pytest_celery.fixtures.backend import celery_backend
from pytest_celery.fixtures.backend import celery_backend_cluster
from pytest_celery.fixtures.backend import celery_backend_cluster_config
from pytest_celery.fixtures.broker import celery_broker
from pytest_celery.fixtures.broker import celery_broker_cluster
from pytest_celery.fixtures.broker import celery_broker_cluster_config
from pytest_celery.fixtures.setup import celery_setup
from pytest_celery.fixtures.setup import celery_setup_app
from pytest_celery.fixtures.setup import celery_setup_cls
from pytest_celery.fixtures.setup import celery_setup_config
from pytest_celery.fixtures.setup import celery_setup_name
from pytest_celery.fixtures.worker import celery_worker
from pytest_celery.fixtures.worker import celery_worker_cluster
from pytest_celery.fixtures.worker import celery_worker_cluster_config
from pytest_celery.vendors import _is_vendor_installed

Check warning on line 41 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L27-L41

Added lines #L27 - L41 were not covered by tests

if _is_vendor_installed("memcached"):
from pytest_celery.vendors.memcached.api import MemcachedTestBackend
from pytest_celery.vendors.memcached.container import MemcachedContainer
from pytest_celery.vendors.memcached.defaults import *
from pytest_celery.vendors.memcached.fixtures import celery_memcached_backend
from pytest_celery.vendors.memcached.fixtures import default_memcached_backend
from pytest_celery.vendors.memcached.fixtures import default_memcached_backend_cls
from pytest_celery.vendors.memcached.fixtures import default_memcached_backend_env
from pytest_celery.vendors.memcached.fixtures import default_memcached_backend_image
from pytest_celery.vendors.memcached.fixtures import default_memcached_backend_ports

Check warning on line 52 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L44-L52

Added lines #L44 - L52 were not covered by tests

if _is_vendor_installed("rabbitmq"):
from pytest_celery.vendors.rabbitmq.api import RabbitMQTestBroker
from pytest_celery.vendors.rabbitmq.container import RabbitMQContainer
from pytest_celery.vendors.rabbitmq.defaults import *
from pytest_celery.vendors.rabbitmq.fixtures import celery_rabbitmq_broker
from pytest_celery.vendors.rabbitmq.fixtures import default_rabbitmq_broker
from pytest_celery.vendors.rabbitmq.fixtures import default_rabbitmq_broker_cls
from pytest_celery.vendors.rabbitmq.fixtures import default_rabbitmq_broker_env
from pytest_celery.vendors.rabbitmq.fixtures import default_rabbitmq_broker_image
from pytest_celery.vendors.rabbitmq.fixtures import default_rabbitmq_broker_ports

Check warning on line 63 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L55-L63

Added lines #L55 - L63 were not covered by tests

if _is_vendor_installed("redis"):
from pytest_celery.vendors.redis.backend.api import RedisTestBackend
from pytest_celery.vendors.redis.backend.defaults import *
from pytest_celery.vendors.redis.backend.fixtures import celery_redis_backend
from pytest_celery.vendors.redis.backend.fixtures import default_redis_backend
from pytest_celery.vendors.redis.backend.fixtures import default_redis_backend_cls
from pytest_celery.vendors.redis.backend.fixtures import default_redis_backend_command
from pytest_celery.vendors.redis.backend.fixtures import default_redis_backend_env
from pytest_celery.vendors.redis.backend.fixtures import default_redis_backend_image
from pytest_celery.vendors.redis.backend.fixtures import default_redis_backend_ports
from pytest_celery.vendors.redis.broker.api import RedisTestBroker
from pytest_celery.vendors.redis.broker.defaults import *
from pytest_celery.vendors.redis.broker.fixtures import celery_redis_broker
from pytest_celery.vendors.redis.broker.fixtures import default_redis_broker
from pytest_celery.vendors.redis.broker.fixtures import default_redis_broker_cls
from pytest_celery.vendors.redis.broker.fixtures import default_redis_broker_command
from pytest_celery.vendors.redis.broker.fixtures import default_redis_broker_env
from pytest_celery.vendors.redis.broker.fixtures import default_redis_broker_image
from pytest_celery.vendors.redis.broker.fixtures import default_redis_broker_ports
from pytest_celery.vendors.redis.container import RedisContainer
from pytest_celery.vendors.redis.defaults import *

Check warning on line 85 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L66-L85

Added lines #L66 - L85 were not covered by tests

if _is_vendor_installed("worker"):
from pytest_celery.vendors.worker.container import CeleryWorkerContainer
from pytest_celery.vendors.worker.content import app
from pytest_celery.vendors.worker.content import utils
from pytest_celery.vendors.worker.fixtures import celery_base_worker_image
from pytest_celery.vendors.worker.fixtures import celery_setup_worker
from pytest_celery.vendors.worker.fixtures import default_worker_app
from pytest_celery.vendors.worker.fixtures import default_worker_app_module
from pytest_celery.vendors.worker.fixtures import default_worker_celery_log_level
from pytest_celery.vendors.worker.fixtures import default_worker_celery_version
from pytest_celery.vendors.worker.fixtures import default_worker_celery_worker_name
from pytest_celery.vendors.worker.fixtures import default_worker_celery_worker_queue
from pytest_celery.vendors.worker.fixtures import default_worker_cls
from pytest_celery.vendors.worker.fixtures import default_worker_command
from pytest_celery.vendors.worker.fixtures import default_worker_container
from pytest_celery.vendors.worker.fixtures import default_worker_container_cls
from pytest_celery.vendors.worker.fixtures import default_worker_container_session_cls
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_signals
from pytest_celery.vendors.worker.fixtures import default_worker_tasks
from pytest_celery.vendors.worker.fixtures import default_worker_utils_module
from pytest_celery.vendors.worker.fixtures import default_worker_volume
from pytest_celery.vendors.worker.tasks import ping
from pytest_celery.vendors.worker.volume import WorkerInitialContent

Check warning on line 111 in src/pytest_celery/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/__init__.py#L88-L111

Added lines #L88 - L111 were not covered by tests


version_info_t = namedtuple(
"version_info_t",
Expand Down
26 changes: 18 additions & 8 deletions src/pytest_celery/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pytest_docker_tools import network

from pytest_celery.vendors import _is_vendor_installed

Check warning on line 7 in src/pytest_celery/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/defaults.py#L7

Added line #L7 was not covered by tests
from pytest_celery.vendors.memcached.defaults import CELERY_MEMCACHED_BACKEND
from pytest_celery.vendors.memcached.defaults import *
from pytest_celery.vendors.rabbitmq.defaults import CELERY_RABBITMQ_BROKER
Expand All @@ -28,15 +29,24 @@
# will automatically add it to the parametrization of every (relevant) test IMPLICITLY!
# Tests that do not rely on default parametrization will not be affected.


ALL_CELERY_BACKENDS = []
ALL_CELERY_BROKERS = []

Check warning on line 34 in src/pytest_celery/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/defaults.py#L33-L34

Added lines #L33 - L34 were not covered by tests

if _is_vendor_installed("redis"):
ALL_CELERY_BACKENDS.append(CELERY_REDIS_BACKEND)
ALL_CELERY_BROKERS.append(CELERY_REDIS_BROKER)

Check warning on line 38 in src/pytest_celery/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/defaults.py#L37-L38

Added lines #L37 - L38 were not covered by tests

if _is_vendor_installed("rabbitmq"):
# Uses Kombu
ALL_CELERY_BROKERS.append(CELERY_RABBITMQ_BROKER)

Check warning on line 42 in src/pytest_celery/defaults.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/defaults.py#L42

Added line #L42 was not covered by tests

# Beta support at the moment, to be used manually
# if can_import_container('memcached'):
# ALL_CELERY_BACKENDS.append(CELERY_MEMCACHED_BACKEND)

# Worker setup is assumed to be always available.
ALL_CELERY_WORKERS = (CELERY_SETUP_WORKER,)
ALL_CELERY_BACKENDS = (
CELERY_REDIS_BACKEND,
# CELERY_MEMCACHED_BACKEND, # Beta support at the moment, to be used manually
)
ALL_CELERY_BROKERS = (
CELERY_REDIS_BROKER,
CELERY_RABBITMQ_BROKER,
)

####################################################################################
# Fixtures
Expand Down
18 changes: 18 additions & 0 deletions src/pytest_celery/vendors/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
"""See :ref:`vendors`."""


def _is_vendor_installed(vendor_name: str) -> bool:

Check warning on line 4 in src/pytest_celery/vendors/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/__init__.py#L4

Added line #L4 was not covered by tests
"""Check if a vendor is installed.
Args:
vendor_name (str): Vendor package name.
Returns:
bool: True if the vendor is installed, False otherwise.
"""

try:
container_module = f"pytest_celery.vendors.{vendor_name}.container"
__import__(container_module)
return True

Check warning on line 17 in src/pytest_celery/vendors/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pytest_celery/vendors/__init__.py#L14-L17

Added lines #L14 - L17 were not covered by tests
except ImportError:
return False
Loading

0 comments on commit c8cf855

Please sign in to comment.