Valerio
03/13/2025, 2:33 PMMarvin
03/13/2025, 2:34 PMpersist_result
parameter: You can set persist_result=False
on each task decorator within your test setup to ensure that results are not persisted.
2. Environment Variable Override: If you have result persistence enabled globally, you can temporarily override this setting in your test environment by setting the PREFECT_TASKS_DEFAULT_PERSIST_RESULT
environment variable to false
.
Here's an example of how you might configure this in a Python test using pytest:
python
from prefect import flow, task
# Example task with persistence disabled for testing
@task(persist_result=False)
def my_task(x):
return x * 2
@flow
def my_flow(x):
return my_task(x)
def test_my_flow():
result = my_flow(10)
assert result == 20
In this example, persist_result=False
ensures that the task's result is not persisted during the test run. Adjust your environment or task decorators accordingly based on your setup.
For more details, you can refer to the Prefect documentation on result persistence and settings reference.