Peter Kim
11/13/2023, 10:11 PMfrom prefect.testing.utilities import prefect_test_harness
from my_project import flow_to_test
def test_flow():
with prefect_test_harness():
flow_to_test()
when I try testing this, it results in this error:
E anyio._backends._asyncio.ExceptionGroup: 2 exceptions were raised in the task group:
E ----------------------------
E Traceback (most recent call last):
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/engine.py", line 1389, in create_task_run_then_submit
E task_run = await create_task_run(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/engine.py", line 1434, in create_task_run
E task_run = await flow_run_context.client.create_task_run(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/client/orchestration.py", line 1980, in create_task_run
E response = await <http://self._client.post|self._client.post>(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1848, in post
E return await self.request(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request
E return await self.send(request, auth=auth, follow_redirects=follow_redirects)
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/client/base.py", line 312, in send
E response.raise_for_status()
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/client/base.py", line 164, in raise_for_status
E raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__
E prefect.exceptions.PrefectHTTPStatusError: Server error '500 Internal Server Error' for url '<http://ephemeral-prefect/api/task_runs/>'
E Response: {'exception_message': 'Internal Server Error'}
E For more information check: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500>
E ----------------------------
E Traceback (most recent call last):
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/engine.py", line 1389, in create_task_run_then_submit
E task_run = await create_task_run(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/engine.py", line 1434, in create_task_run
E task_run = await flow_run_context.client.create_task_run(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/client/orchestration.py", line 1980, in create_task_run
E response = await <http://self._client.post|self._client.post>(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1848, in post
E return await self.request(
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request
E return await self.send(request, auth=auth, follow_redirects=follow_redirects)
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/client/base.py", line 312, in send
E response.raise_for_status()
E File "/Users/psktam/Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/prefect/client/base.py", line 164, in raise_for_status
E raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__
E prefect.exceptions.PrefectHTTPStatusError: Server error '500 Internal Server Error' for url '<http://ephemeral-prefect/api/task_runs/>'
E Response: {'exception_message': 'Internal Server Error'}
E For more information check: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500>
../Library/Caches/pypoetry/virtualenvs/project-RcQVLUoH-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py:595: ExceptionGroup
Marvin
11/13/2023, 10:11 PMwith Flow()
syntax and flow.run()
are now obsolete.
In your test case, you're using prefect_test_harness()
which is also not the recommended way to test flows in Prefect 2.0.
Instead, you should define your flows with the @flow
decorator and tasks with the @task
decorator. To run a flow, you just call the flow directly instead of using my_flow.run()
.
So, your test case should look something like this:
from my_project import flow_to_test
def test_flow():
flow_to_test()
This should resolve the issue you're facing. If you're still encountering problems, it might be helpful to check the Prefect documentation or community resources for more information.Peter Kim
11/13/2023, 10:14 PMprefect_test_harness()
command to test flows with: https://docs.prefect.io/2.14.4/guides/testing/Peter Kim
11/13/2023, 10:14 PMflow_to_test
flow also invokes some subflows. Could that have something to do with this error?Peter Kim
11/13/2023, 10:16 PMPeter Kim
11/13/2023, 10:24 PMNate
11/14/2023, 12:21 AMdo I need to start a local server in order to run this? I was hoping that I wouldn't have to do thatno you dont, i would just have an autouse fixture like this
Peter Kim
11/14/2023, 12:21 AMNate
11/14/2023, 12:21 AMPeter Kim
11/14/2023, 12:22 AMprefect_test_harness()
with the with
statement though?Nate
11/14/2023, 12:22 AMPeter Kim
11/14/2023, 12:22 AMPeter Kim
11/14/2023, 12:22 AMPeter Kim
11/14/2023, 12:23 AMtask_runner
for the parent flow uses DaskTaskRunner
Nate
11/14/2023, 12:23 AMNate
11/14/2023, 12:24 AMPeter Kim
11/14/2023, 12:24 AMPeter Kim
11/14/2023, 12:25 AM