Testing with Zelos SDK¶
The Zelos SDK includes a pytest-based framework for hardware-in-the-loop testing, system validation, and real-time data checks.
Quick Start¶
# Install
pip install zelos-sdk
# Run checks and see the checkerboard
pytest --log-cli-level=INFO
# Also stream every test's trace data to the Agent
pytest --zelos-trace --log-cli-level=INFO
# Stream + record to files (artifacts dir required)
pytest --zelos-trace --zelos-trace-file --zelos-local-artifacts-dir=./artifacts
Minimal test:
import zelos_sdk
motor = zelos_sdk.TraceSourceCache("motor")
motor.add_event("status", [
zelos_sdk.TraceEventFieldMetadata("rpm", zelos_sdk.DataType.Float64),
zelos_sdk.TraceEventFieldMetadata("current", zelos_sdk.DataType.Float64, "A"),
])
def test_reaches_target(check):
motor.status.log(rpm=2000.0, current=12.0) # your bench code logs these
check.that(motor.status.rpm, ">", 1900,
temporal="within_duration", duration_s=0.5)
check.that(motor.status.current, "<", 50,
temporal="for_duration", duration_s=2.0)
A test that requests check connects to the agent on its own. Checks on literals and TraceSourceCache fields, like these two, run without an agent.
What You Get¶
- Checker: expressive, time-aware checks with visual “checkerboard” output
- Recording: automatic
.trzfiles per function/class/module/session - Logging: capture Python logs as trace events and stream to the Agent
- Reports: auto-linked trace files in HTML reports (auto-configured when
pytest-htmlis installed and an artifacts dir is set)
Notes:
- Plugins are auto-registered; no
pytest_pluginssetup required - When recording, pass
--zelos-local-artifacts-dir=./artifacts
How it works¶
- Plugins auto-load via
pytest11entry point (pytest-zelos-plugins), so nopytest_pluginsboilerplate. - Config plugin creates
--zelos-local-artifacts-dir(if provided) and formats--zelos-artifact-basename, then triggerspytest_zelos_configure. -
Trace plugin:
-
Streaming:
--zelos-traceconnects the SDK to the agent at--zelos-trace-urlwhen the session starts, so every test streams its trace data. - Recording:
--zelos-trace-file+ scope fixtures write.trzfiles to the artifacts dir. - Logging: forward Python logs (
--zelos-trace-logging) or print events to stdout (--zelos-trace-stdoutwith--zelos-log). - HTML links: adds
.trzlinks topytest-htmlreports when installed. - Report plugin: if
pytest-htmlis installed, an artifacts dir is set and no--htmlis provided, auto-writes{artifact_basename}-report.htmlin the artifacts dir and enables self-contained HTML. - Agent plugin: provides the
agentfixture. It connects to--zelos-agent-url(thenZELOS_AGENT_URL, thenhttp://localhost:2300) on first use, and opens a per-test checkerboard. - Checker plugin: provides the
checkfixture (agent.check) for time-aware, readable assertions.
Configure¶
- Minimal pytest.ini
- Recording (artifacts dir required): see Trace Recording
- All options: see Configuration
Copy-paste pytest.ini (stream + record + logs)¶
[pytest]
addopts =
-sv
--zelos-trace
--zelos-trace-url=grpc://localhost:2300
--zelos-trace-file
--zelos-trace-file-scope=function
--zelos-local-artifacts-dir=./artifacts
--zelos-trace-logging
--zelos-trace-logging-level=info
log_cli = true
log_cli_level = INFO
Next Steps¶
-
Write clear, time-aware checks without asserts
-
Run the same checks from a markdown notebook — one assertion gates the run, the exit code is the contract
-
Capture
.trzfiles and link them in reports -
Built-in fixtures and how they activate
-
All CLI options and hooks