@@ -73,6 +73,8 @@ These will be used to configure the worker for the tests.
7373 ENV WORKER_NAME=$CELERY_WORKER_NAME
7474 ENV WORKER_QUEUE=$CELERY_WORKER_QUEUE
7575
76+ EXPOSE 5678
77+
7678 ``/src `` is arbitrarily chosen as the working directory to install Celery from.
7779
7880.. code-block :: docker
@@ -136,6 +138,22 @@ to the container instance.
136138 def worker_queue (cls ) -> str :
137139 return " myworker"
138140
141+ .. tip ::
142+
143+ Add the following implementation to enable debugpy for the worker container.
144+
145+ .. code-block :: python
146+
147+ @ classmethod
148+ def ports (cls ) -> dict | None :
149+ return WORKER_DEBUGPY_PORTS
150+
151+ @ classmethod
152+ def command (cls , * args : str , ** kwargs : dict ) -> list[str ]:
153+ return super ().command(* args, debugpy = True , wait_for_client = True , ** kwargs)
154+
155+ The ``WORKER_DEBUGPY_PORTS `` can be imported from the plugin.
156+
139157Next, we build our worker image using the `build <https://github.com/Jc2k/pytest-docker-tools?tab=readme-ov-file#images >`_
140158and `container <https://github.com/Jc2k/pytest-docker-tools?tab=readme-ov-file#containers >`_ fixtures.
141159
@@ -156,11 +174,13 @@ These fixtures may be overridden if required.
156174
157175 myworker_container = container(
158176 image = " {myworker_image.id} " ,
177+ ports = MyWorkerContainer.ports(),
159178 environment = fxtr(" default_worker_env" ),
160179 network = " {default_pytest_celery_network.name} " ,
161180 volumes = {" {default_worker_volume.name} " : defaults.DEFAULT_WORKER_VOLUME },
162181 wrapper_class = MyWorkerContainer,
163182 timeout = defaults.DEFAULT_WORKER_CONTAINER_TIMEOUT ,
183+ command = MyWorkerContainer.command(),
164184 )
165185
166186 Lastly, we wrap the container in a fixture to allow it to be injected into the test environment
0 commit comments