Using the prefect_test_harness across multiple processes via pytest-xdist #18927
Unanswered
jonahduffin
asked this question in
Q&A
Replies: 2 comments
-
@zzstoatzz has suggested that we'll probably have to mess with the DB url based on the pytest workers: |
Beta Was this translation helpful? Give feedback.
0 replies
-
I've tried a lot of things, most recently something like this, which will create a temporary Prefect server if one does not exist yet, and will read in the settings of this server if it does:
This doesn't work great because once the first worker process that created the temp server finishes, the other processes that still need a temp server start failing. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using the prefect_test_harness for my unit tests like so:
However, I also run pytest using the pytest-xdist extension to create multiple processes and run unit tests in parallel. This is resulting in many temporary prefect servers attempting to be spun up at once, and it isn't working well.
I'd like to create a single prefect_test_fixture and share it across multiple threads/processes. Is there a Prefect-recommended way to do so?
Note that pytest-xdist does have some documentation addressing how to make session-scoped fixtures execute only once. But, this won't apply the context of the prefect_test_harness to all of my separate processes, and I need the temporary Prefect settings determined here to apply to all of my processes. My preference is not to pass these settings along via environment variables, because handling environment variables in multi-process unit tests is a headache.
Beta Was this translation helpful? Give feedback.
All reactions