Hi there! what is a proper way to monkeypatch this...
# ask-community
t
Hi there! what is a proper way to monkeypatch this
DaskTaskRunner
argument in a pytest flow run?
Copy code
@flow(
    task_runner=DaskTaskRunner(cluster_kwargs={"n_workers": 1, "threads_per_worker": 8})
)
My pytest will only succeed for the first test and fail for all the others of error:
Copy code
E RuntimeError: Trying to connect to an already closed or closing Cluster LocalCluster(5f8e9acd, '<tcp://127.0.0.1:60043>', workers=0, threads=0, memory=0 B).
I don’t want to manually turn it on while deploying and turn it off while doing local testing.
1
c
good question - right now the best way is probably through some environment variable flag:
Copy code
import os

TASK_RUNNER = None if os.env.get("TEST_MODE") else DaskTaskRunner(...)

@flow(task_runner=TASK_RUNNER)
This will properly short-circuit the initialization of the runner if the flag is present, otherwise it will do as you expect. This is probably a good opportunity for us to provide some standardized hooks for testing, I'll make a note of it!
t
Thanks @Chris White ! It absolutely is a working solution to me. Appreciate your help and commitment of the future improvements!
🙌 1