Richard Sundqvist
02/14/2025, 12:56 PMMarvin
02/14/2025, 12:56 PMPREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS
.
- Event Streaming: The server can stream events to the API via WebSockets, controlled by PREFECT_SERVER_EVENTS_STREAM_OUT_ENABLED
.
For unit testing, Prefect relies on writing tests using frameworks like pytest
, and it is recommended to write tests that fail before your changes and pass afterward to ensure robustness.
For more details, you can refer to the Prefect documentation on ephemeral mode settings.
If you need to explore more about Prefect's public API or specific modules, you can start with the top-level API which includes functions like flow
, task
, get_client
, and more. You can explore further based on your specific needs.
Let me know if there's anything else you need!Richard Sundqvist
02/14/2025, 1:00 PMMarvin
02/14/2025, 1:00 PMprefect_test_harness
utility to set up a temporary Prefect database/server for testing:
python
import pytest
from prefect.testing.utilities import prefect_test_harness
from prefect import flow, task
@pytest.fixture(autouse=True)
def prefect_db():
with prefect_test_harness() as harness:
"""Sets up a temp sandbox Prefect database/server for running tests."""
yield harness
@task
def say_hello(name: str) -> str:
return f"Hello, {name}!"
@flow
def greet(name: str):
return say_hello(name)
def test_greet(prefect_db):
result = greet("World")
assert result == "Hello, World!"
In this example:
- prefect_test_harness()
sets up a temporary Prefect environment for testing.
- A simple flow
and task
are defined to demonstrate the functionality.
- The test_greet
function uses the fixture to ensure the Prefect environment is available during the test.
For more details on Prefect testing utilities, you can refer to the Prefect testing documentation.