You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The examples/ directory serves as the user-facing documentation. Each example is a self-contained application validated by pytest-based tests in tests/examples/.
How validation works
Each example has a corresponding test file in tests/examples/ (e.g., test_state_store.py)
Tests use a DaprRunner helper (defined in tests/examples/conftest.py) that wraps dapr run commands
DaprRunner.run() executes a command and captures stdout; DaprRunner.start()/stop() manage background services
Tests assert that expected output lines appear in the captured output
The runner pins every sidecar listener port the test didn't set itself and blocks until those ports are bindable before launching. Test-pinned ports must stay below 32768 — see the "Port allocation" section in tests/integration/AGENTS.md for the full rationale.
Run examples locally (requires a running Dapr runtime via dapr init):
# All examples
uv run pytest tests/examples/
# Single example
uv run pytest tests/examples/test_state_store.py
In CI (run-tests.yaml), examples run on all supported Python versions (3.10-3.14) on Ubuntu with a full Dapr runtime including Docker, Redis, and (for LLM examples) Ollama.
databricks/fraud_remediation_workflow.py is the runnable half (workflow + activities,
simulates a Lakeflow micro-batch in-process so it needs no pyspark/Databricks). Its counterpart
databricks/fraud_remediation_pipeline.py shows the real pyspark.pipelines wiring but is
illustrative only — it is not executed by tests/examples/ since it requires an actual
Databricks Lakeflow runtime.
Adding a new example
Create a directory under examples/ with a descriptive kebab-case name
Add Python source files and a requirements.txt referencing the needed SDK packages
Add Dapr component YAMLs in a components/ subdirectory if the example uses state, pubsub, etc.
Write a README.md with introduction, pre-requisites, install instructions, and running instructions
Add a corresponding test in tests/examples/test_<example_name>.py:
Use the @pytest.mark.example_dir('<example-name>') marker to set the working directory
Use dapr.run() for scripts that exit on their own, dapr.start()/dapr.stop() for long-running services
Assert expected output lines appear in the captured output
Test locally: uv run pytest tests/examples/test_<example_name>.py
Gotchas
Output format changes break tests: If you modify print statements or log output in SDK code, check whether any test's expected lines in tests/examples/ depend on that output.
Background processes must be cleaned up: The DaprRunner fixture handles cleanup on teardown, but tests should still call dapr.stop() to capture output.
Dapr prefixes output: Application stdout appears as == APP == <line> when run via dapr run.
Redis is available in CI: The CI environment has Redis running on localhost:6379 — most component YAMLs use this.
Some examples need special setup: crypto generates keys, configuration seeds Redis, conversation needs LLM config — check individual READMEs.
Infinite-loop example scripts: Some example scripts (e.g., invoke-caller.py) have while True loops for demo purposes. Tests must either bypass these with HTTP API calls or use dapr.run(until=...) for early termination.