Fixtures & Utilities¶
Built-in pytest fixtures provided by the Zelos SDK plugins.
Core Fixtures¶
check
- Assertion Framework¶
def test_example(check):
"""The check fixture is automatically provided."""
check.that(value, "==", expected)
check.that(signal, ">", threshold, within_duration_s=1.0)
Scope: function Auto-use: No (request explicitly)
zelos_session
- SDK Initialization¶
# Automatically initializes SDK for all tests
# No need to explicitly use—it's auto-enabled
# Configure via command line:
pytest --zelos-trace --zelos-trace-url=grpc://localhost:2300 --zelos-log-level=debug
Scope: session Auto-use: Yes
Trace Fixtures¶
Recording Fixtures¶
These fixtures automatically manage trace file recording at different scopes (active only when --zelos-trace-file
is set and scope matches --zelos-trace-file-scope
). They require --zelos-local-artifacts-dir
to be configured.
# These are auto-use based on --zelos-trace-file-scope setting
# trace_file_session - Records entire session
# trace_file_module - Records per module
# trace_file_class - Records per class
# trace_file_function - Records per function (default)
# Control via command line:
pytest --zelos-trace-file --zelos-local-artifacts-dir=./artifacts --zelos-trace-file-scope=class
All are auto-use when --zelos-trace-file
is enabled.
File naming:
- Default filename:
{artifact_basename}-trace-{sanitized_nodeid}.trz
- Override via
pytest_zelos_trace_file_name(request)
inconftest.py
trace_logging
- Python Log Capture¶
def test_with_logging(trace_logging):
"""Capture Python logging to trace."""
import logging
logging.info("Test started")
logging.error("Something failed")
Scope: session
Auto-use: Yes (when --zelos-trace-logging
enabled)
trace_stdout
- Console Output¶
# Prints trace events to stdout
# Enable with: pytest --zelos-trace-stdout
def test_debug_output():
"""Events print to console for debugging."""
source.log("event", {"value": 123})
# Prints: [TRACE] source/event: value=123
Scope: session
Auto-use: Yes (when --zelos-trace-stdout
enabled)
Utilities¶
Check Configuration¶
from zelos_sdk.pytest.checker import check_config
@check_config(fail_fast=False)
def test_multiple_assertions(check):
"""Continue even if checks fail."""
check.that(1, "==", 1)
check.that(2, "==", 3) # Fails but continues
check.that(3, "==", 3) # Still runs
Custom Operators¶
from zelos_sdk.pytest.checker import ops
def within_range(value, min_val, max_val):
return min_val <= value <= max_val
ops.register_op(ops.DescriptiveOp(
within_range,
"is within range"
))
def test_range(check):
check.that(50, "is within range", 0, args=(100,))