diff --git a/poetry.lock b/poetry.lock index 052ec91c..5e268067 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1960,20 +1960,6 @@ files = [ docker = ">=4.3.1" pytest = ">=6.0.1" -[[package]] -name = "pytest-lazy-fixture" -version = "0.6.3" -description = "It helps to use fixtures in pytest.mark.parametrize" -optional = false -python-versions = "*" -files = [ - {file = "pytest-lazy-fixture-0.6.3.tar.gz", hash = "sha256:0e7d0c7f74ba33e6e80905e9bfd81f9d15ef9a790de97993e34213deb5ad10ac"}, - {file = "pytest_lazy_fixture-0.6.3-py3-none-any.whl", hash = "sha256:e0b379f38299ff27a653f03eaa69b08a6fd4484e46fd1c9907d984b9f9daeda6"}, -] - -[package.dependencies] -pytest = ">=3.2.5" - [[package]] name = "pytest-rerunfailures" version = "13.0" @@ -3107,4 +3093,4 @@ celery = ["celery"] [metadata] lock-version = "2.0" python-versions = ">= 3.8,<4.0" -content-hash = "5bb37c8fd2af4c6e2fab9647db19419eefb05457c25d7b20851b2d5c7f8c0043" +content-hash = "1a76f9c00e2c8254d18163ec401b01cdb21ead266c91446743c69b268ee75783" diff --git a/pyproject.toml b/pyproject.toml index 5a596f7d..ff99f9bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,7 +119,6 @@ optional = true pytest = "^7.4.4" coverage = "^7.0.0" pytest-sugar = { version = "^1.0.0", python = ">=3.8,<4.0" } -pytest-lazy-fixture = "^0.6.3" pytest-cov = "^4.0.0" pytest-xdist = "^3.1.0" pytest-subtests = "^0.11.0" diff --git a/tests/integration/api/test_backend.py b/tests/integration/api/test_backend.py index a15d6dfc..706fbb47 100644 --- a/tests/integration/api/test_backend.py +++ b/tests/integration/api/test_backend.py @@ -1,27 +1,22 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_BACKEND -from pytest_celery import CELERY_BACKEND_CLUSTER from pytest_celery import CeleryBackendCluster from pytest_celery import CeleryTestBackend +from pytest_celery import CeleryTestCluster +from pytest_celery import CeleryTestNode +from tests.integration.api.test_base import BaseCluster +from tests.integration.api.test_base import BaseNodes -@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_BACKEND)]) -class test_celey_test_backend: - def test_app(self, backend: CeleryTestBackend): - assert backend.app is None +class test_celey_test_backend(BaseNodes): + @pytest.fixture + def node(self, celery_backend: CeleryTestBackend) -> CeleryTestNode: + return celery_backend -@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BACKEND_CLUSTER)]) -class test_celery_backend_cluster: - def test_app(self, cluster: CeleryBackendCluster): - backend: CeleryTestBackend - for backend in cluster: - assert backend.app is None - - def test_config(self, cluster: CeleryBackendCluster): - expected_keys = {"urls", "host_urls"} - assert set(cluster.config().keys()) == expected_keys +class test_celery_backend_cluster(BaseCluster): + @pytest.fixture + def cluster(self, celery_backend_cluster: CeleryBackendCluster) -> CeleryTestCluster: + return celery_backend_cluster diff --git a/tests/integration/api/test_base.py b/tests/integration/api/test_base.py index 116af455..64a657de 100644 --- a/tests/integration/api/test_base.py +++ b/tests/integration/api/test_base.py @@ -1,20 +1,19 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture from pytest_celery import CeleryTestCluster from pytest_celery import CeleryTestNode from pytest_celery import RedisTestBackend -from tests.defaults import ALL_CLUSTERS_FIXTURES -from tests.defaults import ALL_NODES_FIXTURES -@pytest.mark.parametrize("node", lazy_fixture(ALL_NODES_FIXTURES)) -class test_celery_test_node: +class BaseNodes: def test_ready(self, node: CeleryTestNode): assert node.ready() + def test_app(self, node: CeleryTestNode): + assert node.app is None + def test_logs(self, node: CeleryTestNode): node.logs() @@ -62,10 +61,18 @@ def test_assert_log_does_not_exist(self, node: CeleryTestNode): pass -@pytest.mark.parametrize("cluster", lazy_fixture(ALL_CLUSTERS_FIXTURES)) -class test_celery_test_cluster: +class BaseCluster: def test_ready(self, cluster: CeleryTestCluster): assert cluster.ready() def test_teardown(self, cluster: CeleryTestCluster): cluster.teardown() + + def test_app(self, cluster: CeleryTestCluster): + node: CeleryTestNode + for node in cluster: + assert node.app is None + + def test_config(self, cluster: CeleryTestCluster): + expected_keys = {"urls", "host_urls"} + assert set(cluster.config().keys()) == expected_keys diff --git a/tests/integration/api/test_broker.py b/tests/integration/api/test_broker.py index 850f5586..6144030a 100644 --- a/tests/integration/api/test_broker.py +++ b/tests/integration/api/test_broker.py @@ -1,27 +1,22 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_BROKER -from pytest_celery import CELERY_BROKER_CLUSTER from pytest_celery import CeleryBrokerCluster from pytest_celery import CeleryTestBroker +from pytest_celery import CeleryTestCluster +from pytest_celery import CeleryTestNode +from tests.integration.api.test_base import BaseCluster +from tests.integration.api.test_base import BaseNodes -@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_BROKER)]) -class test_celery_test_broker: - def test_app(self, broker: CeleryTestBroker): - assert broker.app is None +class test_celery_test_broker(BaseNodes): + @pytest.fixture + def node(self, celery_broker: CeleryTestBroker) -> CeleryTestNode: + return celery_broker -@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BROKER_CLUSTER)]) -class test_celery_broker_cluster: - def test_app(self, cluster: CeleryBrokerCluster): - broker: CeleryTestBroker - for broker in cluster: - assert broker.app is None - - def test_config(self, cluster: CeleryBrokerCluster): - expected_keys = {"urls", "host_urls"} - assert set(cluster.config().keys()) == expected_keys +class test_celery_broker_cluster(BaseCluster): + @pytest.fixture + def cluster(self, celery_broker_cluster: CeleryBrokerCluster) -> CeleryTestCluster: + return celery_broker_cluster diff --git a/tests/integration/api/test_container.py b/tests/integration/api/test_container.py index 181d6007..0bec3a5d 100644 --- a/tests/integration/api/test_container.py +++ b/tests/integration/api/test_container.py @@ -1,13 +1,17 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture from pytest_celery import CeleryTestContainer from tests.defaults import ALL_COMPONENTS_FIXTURES -@pytest.mark.parametrize("container", lazy_fixture(ALL_COMPONENTS_FIXTURES)) +@pytest.fixture +def container(request): + return request.getfixturevalue(request.param) + + +@pytest.mark.parametrize("container", ALL_COMPONENTS_FIXTURES, indirect=["container"]) class test_celery_test_container: def test_client(self, container: CeleryTestContainer): assert container.client diff --git a/tests/integration/api/test_worker.py b/tests/integration/api/test_worker.py index 28811511..190d58d0 100644 --- a/tests/integration/api/test_worker.py +++ b/tests/integration/api/test_worker.py @@ -2,48 +2,55 @@ import pytest from celery import Celery -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_WORKER -from pytest_celery import CELERY_WORKER_CLUSTER +from pytest_celery import CeleryTestCluster +from pytest_celery import CeleryTestNode from pytest_celery import CeleryTestWorker from pytest_celery import CeleryWorkerCluster from pytest_celery import CeleryWorkerContainer +from tests.integration.api.test_base import BaseCluster +from tests.integration.api.test_base import BaseNodes -@pytest.mark.parametrize("worker", [lazy_fixture(CELERY_WORKER)]) -class test_celey_test_worker: - def test_app(self, worker: CeleryTestWorker, celery_setup_app: Celery): - assert worker.app is celery_setup_app +class test_celey_test_worker(BaseNodes): + @pytest.fixture + def node(self, celery_worker: CeleryTestWorker) -> CeleryTestNode: + return celery_worker - def test_version(self, worker: CeleryTestWorker): - assert worker.version == CeleryWorkerContainer.version() + def test_app(self, celery_worker: CeleryTestWorker, celery_setup_app: Celery): + assert celery_worker.app is celery_setup_app - def test_hostname(self, worker: CeleryTestWorker): - hostname = worker.hostname() + def test_version(self, celery_worker: CeleryTestWorker): + assert celery_worker.version == CeleryWorkerContainer.version() + + def test_hostname(self, celery_worker: CeleryTestWorker): + hostname = celery_worker.hostname() assert "@" in hostname - assert worker.worker_name in hostname.split("@")[0] - assert worker.container.id[:12] in hostname.split("@")[1] + assert celery_worker.worker_name in hostname.split("@")[0] + assert celery_worker.container.id[:12] in hostname.split("@")[1] + + def test_wait_for_log(self, celery_worker: CeleryTestWorker): + log = f"{celery_worker.hostname()} v{celery_worker.version}" + celery_worker.wait_for_log(log, "test_celey_test_worker.test_wait_for_log") - def test_wait_for_log(self, worker: CeleryTestWorker): - log = f"{worker.hostname()} v{worker.version}" - worker.wait_for_log(log, "test_celey_test_worker.test_wait_for_log") + def test_assert_log_exists(self, celery_worker: CeleryTestWorker): + log = f"{celery_worker.hostname()} v{celery_worker.version}" + celery_worker.assert_log_exists(log, "test_celey_test_worker.test_assert_log_exists") - def test_assert_log_exists(self, worker: CeleryTestWorker): - log = f"{worker.hostname()} v{worker.version}" - worker.assert_log_exists(log, "test_celey_test_worker.test_assert_log_exists") +class test_celery_worker_cluster(BaseCluster): + @pytest.fixture + def cluster(self, celery_worker_cluster: CeleryWorkerCluster) -> CeleryTestCluster: + return celery_worker_cluster -@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_WORKER_CLUSTER)]) -class test_celery_worker_cluster: - def test_app(self, cluster: CeleryWorkerCluster, celery_setup_app: Celery): + def test_app(self, celery_worker_cluster: CeleryWorkerCluster, celery_setup_app: Celery): worker: CeleryTestWorker - for worker in cluster: + for worker in celery_worker_cluster: assert worker.app is celery_setup_app - def test_config(self, cluster: CeleryWorkerCluster): + def test_config(self, celery_worker_cluster: CeleryWorkerCluster): with pytest.raises(NotImplementedError): - cluster.config() + celery_worker_cluster.config() - def test_versions(self, cluster: CeleryWorkerCluster): - assert cluster.versions == {CeleryWorkerContainer.version()} + def test_versions(self, celery_worker_cluster: CeleryWorkerCluster): + assert celery_worker_cluster.versions == {CeleryWorkerContainer.version()} diff --git a/tests/integration/vendors/test_memcached.py b/tests/integration/vendors/test_memcached.py index 42840c8d..4d86af47 100644 --- a/tests/integration/vendors/test_memcached.py +++ b/tests/integration/vendors/test_memcached.py @@ -1,15 +1,18 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_MEMCACHED_BACKEND from pytest_celery import MemcachedContainer from pytest_celery import MemcachedTestBackend from tests.defaults import ALL_MEMCACHED_FIXTURES -@pytest.mark.parametrize("container", lazy_fixture(ALL_MEMCACHED_FIXTURES)) +@pytest.fixture +def container(request): + return request.getfixturevalue(request.param) + + +@pytest.mark.parametrize("container", ALL_MEMCACHED_FIXTURES, indirect=["container"]) class test_memcached_container: def test_client(self, container: MemcachedContainer): assert container.client @@ -26,10 +29,9 @@ def test_celeryconfig(self, container: MemcachedContainer): assert container.prefix() in config["host_url"] -@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_MEMCACHED_BACKEND)]) class test_memcached_test_backend: - def test_config(self, backend: MemcachedTestBackend): + def test_config(self, celery_memcached_backend: MemcachedTestBackend): expected_keys = {"url", "host_url", "hostname", "port"} - assert set(backend.config().keys()) == expected_keys - assert backend.container.prefix() in backend.config()["url"] - assert backend.container.prefix() in backend.config()["host_url"] + assert set(celery_memcached_backend.config().keys()) == expected_keys + assert celery_memcached_backend.container.prefix() in celery_memcached_backend.config()["url"] + assert celery_memcached_backend.container.prefix() in celery_memcached_backend.config()["host_url"] diff --git a/tests/integration/vendors/test_rabbitmq.py b/tests/integration/vendors/test_rabbitmq.py index 0673afc7..840b3c13 100644 --- a/tests/integration/vendors/test_rabbitmq.py +++ b/tests/integration/vendors/test_rabbitmq.py @@ -2,15 +2,18 @@ import pytest from kombu import Connection -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_RABBITMQ_BROKER from pytest_celery import RabbitMQContainer from pytest_celery import RabbitMQTestBroker from tests.defaults import ALL_RABBITMQ_FIXTURES -@pytest.mark.parametrize("container", lazy_fixture(ALL_RABBITMQ_FIXTURES)) +@pytest.fixture +def container(request): + return request.getfixturevalue(request.param) + + +@pytest.mark.parametrize("container", ALL_RABBITMQ_FIXTURES, indirect=["container"]) class test_rabbitmq_container: def test_client(self, container: RabbitMQContainer): c: Connection = container.client @@ -28,10 +31,9 @@ def test_celeryconfig(self, container: RabbitMQContainer): assert container.prefix() in config["host_url"] -@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_RABBITMQ_BROKER)]) class test_rabbitmq_test_broker: - def test_config(self, broker: RabbitMQTestBroker): + def test_config(self, celery_rabbitmq_broker: RabbitMQTestBroker): expected_keys = {"url", "host_url", "hostname", "port", "vhost"} - assert set(broker.config().keys()) == expected_keys - assert broker.container.prefix() in broker.config()["url"] - assert broker.container.prefix() in broker.config()["host_url"] + assert set(celery_rabbitmq_broker.config().keys()) == expected_keys + assert celery_rabbitmq_broker.container.prefix() in celery_rabbitmq_broker.config()["url"] + assert celery_rabbitmq_broker.container.prefix() in celery_rabbitmq_broker.config()["host_url"] diff --git a/tests/integration/vendors/test_redis.py b/tests/integration/vendors/test_redis.py index cf13a57c..b26af071 100644 --- a/tests/integration/vendors/test_redis.py +++ b/tests/integration/vendors/test_redis.py @@ -1,17 +1,19 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_REDIS_BACKEND -from pytest_celery import CELERY_REDIS_BROKER from pytest_celery import RedisContainer from pytest_celery import RedisTestBackend from pytest_celery import RedisTestBroker from tests.defaults import ALL_REDIS_FIXTURES -@pytest.mark.parametrize("container", lazy_fixture(ALL_REDIS_FIXTURES)) +@pytest.fixture +def container(request): + return request.getfixturevalue(request.param) + + +@pytest.mark.parametrize("container", ALL_REDIS_FIXTURES, indirect=["container"]) class test_redis_container: def test_client(self, container: RedisContainer): assert container.client @@ -28,19 +30,17 @@ def test_celeryconfig(self, container: RedisContainer): assert container.prefix() in config["host_url"] -@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_REDIS_BACKEND)]) class test_redis_test_backend: - def test_config(self, backend: RedisTestBackend): + def test_config(self, celery_redis_backend: RedisTestBackend): expected_keys = {"url", "host_url", "hostname", "port", "vhost"} - assert set(backend.config().keys()) == expected_keys - assert backend.container.prefix() in backend.config()["url"] - assert backend.container.prefix() in backend.config()["host_url"] + assert set(celery_redis_backend.config().keys()) == expected_keys + assert celery_redis_backend.container.prefix() in celery_redis_backend.config()["url"] + assert celery_redis_backend.container.prefix() in celery_redis_backend.config()["host_url"] -@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_REDIS_BROKER)]) class test_redis_test_broker: - def test_config(self, broker: RedisTestBroker): + def test_config(self, celery_redis_broker: RedisTestBroker): expected_keys = {"url", "host_url", "hostname", "port", "vhost"} - assert set(broker.config().keys()) == expected_keys - assert broker.container.prefix() in broker.config()["url"] - assert broker.container.prefix() in broker.config()["host_url"] + assert set(celery_redis_broker.config().keys()) == expected_keys + assert celery_redis_broker.container.prefix() in celery_redis_broker.config()["url"] + assert celery_redis_broker.container.prefix() in celery_redis_broker.config()["host_url"] diff --git a/tests/integration/vendors/test_worker.py b/tests/integration/vendors/test_worker.py index 9160b8ab..5b59a394 100644 --- a/tests/integration/vendors/test_worker.py +++ b/tests/integration/vendors/test_worker.py @@ -3,9 +3,7 @@ from types import ModuleType import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_SETUP_WORKER from pytest_celery import DEFAULT_WORKER_ENV from pytest_celery import CeleryBackendCluster from pytest_celery import CeleryTestWorker @@ -13,7 +11,12 @@ from tests.defaults import ALL_WORKERS_FIXTURES -@pytest.mark.parametrize("container", lazy_fixture(ALL_WORKERS_FIXTURES)) +@pytest.fixture +def container(request): + return request.getfixturevalue(request.param) + + +@pytest.mark.parametrize("container", ALL_WORKERS_FIXTURES, indirect=["container"]) class test_celery_worker_container: def test_client(self, container: CeleryWorkerContainer): assert container.client @@ -48,8 +51,7 @@ def test_replacing_app_module(self, container: CeleryWorkerContainer, default_wo assert container.app_module() == default_worker_app_module -@pytest.mark.parametrize("worker", [lazy_fixture(CELERY_SETUP_WORKER)]) class test_base_test_worker: - def test_config(self, worker: CeleryTestWorker): + def test_config(self, celery_setup_worker: CeleryTestWorker): with pytest.raises(NotImplementedError): - worker.config() + celery_setup_worker.config() diff --git a/tests/unit/api/test_backend.py b/tests/unit/api/test_backend.py index edc48ce5..99e38dcb 100644 --- a/tests/unit/api/test_backend.py +++ b/tests/unit/api/test_backend.py @@ -2,43 +2,42 @@ import pytest from celery import Celery -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_BACKEND -from pytest_celery import CELERY_BACKEND_CLUSTER from pytest_celery import DEFAULT_WORKER_ENV from pytest_celery import CeleryBackendCluster from pytest_celery import CeleryTestBackend -@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_BACKEND)]) class test_celey_test_backend: - def test_default_config_format(self, backend: CeleryTestBackend): - assert backend.default_config()["url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"] - assert backend.default_config()["host_url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"] + def test_default_config_format(self, celery_backend: CeleryTestBackend): + assert celery_backend.default_config()["url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"] + assert celery_backend.default_config()["host_url"] == DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"] - def test_restart_no_app(self, backend: CeleryTestBackend): - assert backend.app is None - backend.restart() + def test_restart_no_app(self, celery_backend: CeleryTestBackend): + assert celery_backend.app is None + celery_backend.restart() - def test_restart_with_app(self, backend: CeleryTestBackend, celery_setup_app: Celery): - backend._app = celery_setup_app + def test_restart_with_app(self, celery_backend: CeleryTestBackend, celery_setup_app: Celery): + celery_backend._app = celery_setup_app assert "result_backend" not in celery_setup_app.conf.changes - backend.restart() + celery_backend.restart() assert "result_backend" in celery_setup_app.conf.changes -@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BACKEND_CLUSTER)]) class test_celery_backend_cluster: - def test_default_config_format(self, cluster: CeleryBackendCluster): - assert cluster.default_config()["urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]] - assert cluster.default_config()["host_urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]] + def test_default_config_format(self, celery_backend_cluster: CeleryBackendCluster): + assert celery_backend_cluster.default_config()["urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]] + assert celery_backend_cluster.default_config()["host_urls"] == [DEFAULT_WORKER_ENV["CELERY_RESULT_BACKEND"]] class test_disabling_cluster: @pytest.fixture def celery_backend_cluster(self) -> CeleryBackendCluster: return None - def test_disabling_backend_cluster(self, cluster: CeleryBackendCluster, celery_backend_cluster_config: dict): - assert cluster is None + def test_disabling_backend_cluster( + self, + celery_backend_cluster: CeleryBackendCluster, + celery_backend_cluster_config: dict, + ): + assert celery_backend_cluster is None assert celery_backend_cluster_config is None diff --git a/tests/unit/api/test_broker.py b/tests/unit/api/test_broker.py index 4cb9b93b..5779d400 100644 --- a/tests/unit/api/test_broker.py +++ b/tests/unit/api/test_broker.py @@ -2,43 +2,40 @@ import pytest from celery import Celery -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_BROKER -from pytest_celery import CELERY_BROKER_CLUSTER from pytest_celery import DEFAULT_WORKER_ENV from pytest_celery import CeleryBrokerCluster from pytest_celery import CeleryTestBroker -@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_BROKER)]) class test_celey_test_broker: - def test_default_config_format(self, broker: CeleryTestBroker): - assert broker.default_config()["url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"] - assert broker.default_config()["host_url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"] + def test_default_config_format(self, celery_broker: CeleryTestBroker): + assert celery_broker.default_config()["url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"] + assert celery_broker.default_config()["host_url"] == DEFAULT_WORKER_ENV["CELERY_BROKER_URL"] - def test_restart_no_app(self, broker: CeleryTestBroker): - assert broker.app is None - broker.restart() + def test_restart_no_app(self, celery_broker: CeleryTestBroker): + assert celery_broker.app is None + celery_broker.restart() - def test_restart_with_app(self, broker: CeleryTestBroker, celery_setup_app: Celery): - broker._app = celery_setup_app + def test_restart_with_app(self, celery_broker: CeleryTestBroker, celery_setup_app: Celery): + celery_broker._app = celery_setup_app assert "broker_url" not in celery_setup_app.conf.changes - broker.restart() + celery_broker.restart() assert "broker_url" in celery_setup_app.conf.changes -@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BROKER_CLUSTER)]) class test_celery_broker_cluster: - def test_default_config_format(self, cluster: CeleryBrokerCluster): - assert cluster.default_config()["urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]] - assert cluster.default_config()["host_urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]] + def test_default_config_format(self, celery_broker_cluster: CeleryBrokerCluster): + assert celery_broker_cluster.default_config()["urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]] + assert celery_broker_cluster.default_config()["host_urls"] == [DEFAULT_WORKER_ENV["CELERY_BROKER_URL"]] class test_disabling_cluster: @pytest.fixture def celery_broker_cluster(self) -> CeleryBrokerCluster: return None - def test_disabling_broker_cluster(self, cluster: CeleryBrokerCluster, celery_broker_cluster_config: dict): - assert cluster is None + def test_disabling_broker_cluster( + self, celery_broker_cluster: CeleryBrokerCluster, celery_broker_cluster_config: dict + ): + assert celery_broker_cluster is None assert celery_broker_cluster_config is None diff --git a/tests/unit/api/test_worker.py b/tests/unit/api/test_worker.py index 946c622c..688771e8 100644 --- a/tests/unit/api/test_worker.py +++ b/tests/unit/api/test_worker.py @@ -1,44 +1,38 @@ from __future__ import annotations -import pytest from celery import Celery -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_WORKER -from pytest_celery import CELERY_WORKER_CLUSTER from pytest_celery import CeleryTestWorker from pytest_celery import CeleryWorkerCluster -@pytest.mark.parametrize("worker", [lazy_fixture(CELERY_WORKER)]) class test_celey_test_worker: - def test_app(self, worker: CeleryTestWorker, celery_setup_app: Celery): - assert worker.app is celery_setup_app + def test_app(self, celery_worker: CeleryTestWorker, celery_setup_app: Celery): + assert celery_worker.app is celery_setup_app - def test_version(self, worker: CeleryTestWorker): - worker.version - worker.container.version.assert_called_once() + def test_version(self, celery_worker: CeleryTestWorker): + celery_worker.version + celery_worker.container.version.assert_called_once() - def test_log_level(self, worker: CeleryTestWorker): - worker.log_level - worker.container.log_level.assert_called_once() + def test_log_level(self, celery_worker: CeleryTestWorker): + celery_worker.log_level + celery_worker.container.log_level.assert_called_once() - def test_worker_name(self, worker: CeleryTestWorker): - worker.worker_name - worker.container.worker_name.assert_called_once() + def test_worker_name(self, celery_worker: CeleryTestWorker): + celery_worker.worker_name + celery_worker.container.worker_name.assert_called_once() - def test_worker_queue(self, worker: CeleryTestWorker): - worker.worker_queue - worker.container.worker_queue.assert_called_once() + def test_worker_queue(self, celery_worker: CeleryTestWorker): + celery_worker.worker_queue + celery_worker.container.worker_queue.assert_called_once() -@pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_WORKER_CLUSTER)]) class test_celery_worker_cluster: - def test_app(self, cluster: CeleryWorkerCluster, celery_setup_app: Celery): - for node in cluster: + def test_app(self, celery_worker_cluster: CeleryWorkerCluster, celery_setup_app: Celery): + for node in celery_worker_cluster: assert node.app is celery_setup_app - def test_versions(self, cluster: CeleryWorkerCluster): - cluster.versions - for node in cluster: + def test_versions(self, celery_worker_cluster: CeleryWorkerCluster): + celery_worker_cluster.versions + for node in celery_worker_cluster: node.container.version.assert_called_once() diff --git a/tests/unit/vendors/test_memcached.py b/tests/unit/vendors/test_memcached.py index c0e9c7f6..57df7270 100644 --- a/tests/unit/vendors/test_memcached.py +++ b/tests/unit/vendors/test_memcached.py @@ -1,9 +1,7 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_MEMCACHED_BACKEND from pytest_celery import MEMCACHED_ENV from pytest_celery import MEMCACHED_IMAGE from pytest_celery import MEMCACHED_PORTS @@ -29,10 +27,9 @@ def test_prefix(self): assert MemcachedContainer.prefix() == MEMCACHED_PREFIX -@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_MEMCACHED_BACKEND)]) class test_memcached_backend_api: @pytest.mark.skip(reason="Placeholder") - def test_placeholder(self, backend: MemcachedTestBackend): + def test_placeholder(self, celery_memcached_backend: MemcachedTestBackend): # The class MemcachedTestBackend is currently a placeholder # so we don't have any specific tests for it yet. # This test suite is pre-configured to test the MemcachedTestBackend diff --git a/tests/unit/vendors/test_rabbitmq.py b/tests/unit/vendors/test_rabbitmq.py index 47dae9a6..7b4677dd 100644 --- a/tests/unit/vendors/test_rabbitmq.py +++ b/tests/unit/vendors/test_rabbitmq.py @@ -1,9 +1,7 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_RABBITMQ_BROKER from pytest_celery import RABBITMQ_ENV from pytest_celery import RABBITMQ_IMAGE from pytest_celery import RABBITMQ_PORTS @@ -30,10 +28,9 @@ def test_prefix(self): assert RabbitMQContainer.prefix() == RABBITMQ_PREFIX -@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_RABBITMQ_BROKER)]) class test_rabbitmq_broker_api: @pytest.mark.skip(reason="Placeholder") - def test_placeholder(self, broker: RabbitMQTestBroker): + def test_placeholder(self, celery_rabbitmq_broker: RabbitMQTestBroker): # The class RabbitMQTestBroker is currently a placeholder # so we don't have any specific tests for it yet. # This test suite is pre-configured to test the RabbitMQTestBroker diff --git a/tests/unit/vendors/test_redis.py b/tests/unit/vendors/test_redis.py index 7b24e163..4fd37d59 100644 --- a/tests/unit/vendors/test_redis.py +++ b/tests/unit/vendors/test_redis.py @@ -1,10 +1,7 @@ from __future__ import annotations import pytest -from pytest_lazyfixture import lazy_fixture -from pytest_celery import CELERY_REDIS_BACKEND -from pytest_celery import CELERY_REDIS_BROKER from pytest_celery import REDIS_ENV from pytest_celery import REDIS_IMAGE from pytest_celery import REDIS_PORTS @@ -31,18 +28,16 @@ def test_prefix(self): assert RedisContainer.prefix() == REDIS_PREFIX -@pytest.mark.parametrize("backend", [lazy_fixture(CELERY_REDIS_BACKEND)]) class test_redis_backend_api: @pytest.mark.skip(reason="RedisTestBackend.teardown() breaks the testing environment") - def test_teardown(self, backend: RedisTestBackend): - backend.teardown() - backend.container.teardown.assert_called_once() + def test_teardown(self, celery_redis_backend: RedisTestBackend): + celery_redis_backend.teardown() + celery_redis_backend.container.teardown.assert_called_once() -@pytest.mark.parametrize("broker", [lazy_fixture(CELERY_REDIS_BROKER)]) class test_redis_broker_api: @pytest.mark.skip(reason="Placeholder") - def test_placeholder(self, broker: RedisTestBroker): + def test_placeholder(self, celery_redis_broker: RedisTestBroker): # The class RedisTestBroker is currently a placeholder # so we don't have any specific tests for it yet. # This test suite is pre-configured to test the RedisTestBroker