From 2dc8484c6f9331bc0f68b159e2610b02e9752e54 Mon Sep 17 00:00:00 2001 From: Tomer Nosrati Date: Thu, 19 Oct 2023 21:42:16 +0300 Subject: [PATCH] Cleanup --- src/pytest_celery/api/backend.py | 2 +- src/pytest_celery/api/base.py | 4 ++++ src/pytest_celery/api/broker.py | 2 +- src/pytest_celery/api/worker.py | 4 ---- tests/integration/api/test_backend.py | 3 +++ tests/integration/api/{test_cluster.py => test_base.py} | 0 tests/integration/api/test_broker.py | 3 +++ tests/unit/api/test_base.py | 7 +++++++ tests/unit/api/test_worker.py | 4 ---- 9 files changed, 19 insertions(+), 10 deletions(-) rename tests/integration/api/{test_cluster.py => test_base.py} (100%) diff --git a/src/pytest_celery/api/backend.py b/src/pytest_celery/api/backend.py index 4efddb2b..f24ca541 100644 --- a/src/pytest_celery/api/backend.py +++ b/src/pytest_celery/api/backend.py @@ -18,7 +18,7 @@ def default_config(cls) -> dict: def restart(self) -> None: super().restart() - self._app.conf.update( + self.app.conf.update( result_backend=self.config()["local_url"], ) diff --git a/src/pytest_celery/api/base.py b/src/pytest_celery/api/base.py index 40f8eb0c..96daa525 100644 --- a/src/pytest_celery/api/base.py +++ b/src/pytest_celery/api/base.py @@ -22,6 +22,10 @@ def __init__(self, container: CeleryTestContainer, app: Celery = None) -> None: def container(self) -> CeleryTestContainer: return self._container + @property + def app(self) -> Celery: + return self._app + def ready(self) -> bool: return self.container.ready() diff --git a/src/pytest_celery/api/broker.py b/src/pytest_celery/api/broker.py index c64ef791..131ead67 100644 --- a/src/pytest_celery/api/broker.py +++ b/src/pytest_celery/api/broker.py @@ -18,7 +18,7 @@ def default_config(cls) -> dict: def restart(self) -> None: super().restart() - self._app.conf.update( + self.app.conf.update( broker_url=self.config()["local_url"], ) diff --git a/src/pytest_celery/api/worker.py b/src/pytest_celery/api/worker.py index c8e85080..bb4ffd3e 100644 --- a/src/pytest_celery/api/worker.py +++ b/src/pytest_celery/api/worker.py @@ -18,10 +18,6 @@ def __init__(self, container: CeleryTestContainer, app: Celery): # Helps with autocomplete in the IDE self.container: CeleryWorkerContainer - @property - def app(self) -> Celery: - return self._app - @property def version(self) -> str: if hasattr(self.container, "version"): diff --git a/tests/integration/api/test_backend.py b/tests/integration/api/test_backend.py index 676d1864..ddbcc4ea 100644 --- a/tests/integration/api/test_backend.py +++ b/tests/integration/api/test_backend.py @@ -12,6 +12,9 @@ class test_celey_test_backend: def test_ready(self, node: CeleryTestBackend): assert node.ready() + def test_app(self, node: CeleryTestBackend): + assert node.app is None + @pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BACKEND_CLUSTER)]) class test_celery_backend_cluster: diff --git a/tests/integration/api/test_cluster.py b/tests/integration/api/test_base.py similarity index 100% rename from tests/integration/api/test_cluster.py rename to tests/integration/api/test_base.py diff --git a/tests/integration/api/test_broker.py b/tests/integration/api/test_broker.py index 085b9c22..baf419e0 100644 --- a/tests/integration/api/test_broker.py +++ b/tests/integration/api/test_broker.py @@ -12,6 +12,9 @@ class test_celery_test_broker: def test_ready(self, node: CeleryTestBroker): assert node.ready() + def test_app(self, node: CeleryTestBroker): + assert node.app is None + @pytest.mark.parametrize("cluster", [lazy_fixture(CELERY_BROKER_CLUSTER)]) class test_celery_broker_cluster: diff --git a/tests/unit/api/test_base.py b/tests/unit/api/test_base.py index c2ff3c84..1aedab31 100644 --- a/tests/unit/api/test_base.py +++ b/tests/unit/api/test_base.py @@ -1,3 +1,5 @@ +from celery import Celery + from pytest_celery import CeleryTestCluster from pytest_celery import CeleryTestContainer from pytest_celery import CeleryTestNode @@ -8,6 +10,11 @@ def test_ready(self, unit_tests_container: CeleryTestContainer): node = CeleryTestNode(unit_tests_container) assert node.ready() + def test_app(self, unit_tests_container: CeleryTestContainer): + expected_app = Celery() + node = CeleryTestNode(unit_tests_container, expected_app) + assert node.app is expected_app + def test_default_config_format(self, unit_tests_container: CeleryTestContainer): node = CeleryTestNode(unit_tests_container) assert node.default_config() == dict() diff --git a/tests/unit/api/test_worker.py b/tests/unit/api/test_worker.py index d48ae20b..54120843 100644 --- a/tests/unit/api/test_worker.py +++ b/tests/unit/api/test_worker.py @@ -10,10 +10,6 @@ def test_ready(self, unit_tests_container: CeleryTestContainer, celery_setup_app node = CeleryTestWorker(unit_tests_container, celery_setup_app) assert node.ready() - def test_app(self, unit_tests_container: CeleryTestContainer, celery_setup_app: Celery): - node = CeleryTestWorker(unit_tests_container, celery_setup_app) - assert node.app is celery_setup_app - def test_default_config_format( self, unit_tests_container: CeleryTestContainer,