Decorator
@metric
Register a metric resource that yields a Metric instance and optionally a final value. Signature:
Returns: Decorated function registered as a metric resource
Generator Requirements:
- Must
yieldaMetricinstance first (this gets injected) - Optionally
yielda final calculated value (becomesMetricResult.value) - Can assert on metric properties after all data is collected
Classes
Metric
Thread-safe class for recording data and computing statistical properties. Attributes:
Methods:
Statistical Properties:
All properties are computed lazily and cached. Recording happens when you call
add_record(...) (manually) or when you use with metrics(...) to record assertion pass/fail outcomes.
Example:
MetricMetadata
Metadata tracking metric lifecycle and contributors. Attributes:
Example:
MetricResult
Result captured when a metric resource completes. Attributes:
Note:
MetricResult instances are automatically collected and included in merit run reports.
Example:
Context Manager
metrics()
Attach metrics to assertions for automatic data collection. Signature:
Returns: Context manager that captures assertion results
Behavior:
- When an assertion passes inside the context, records
Trueto all metrics - When an assertion fails, records
Falseto all metrics - Multiple assertions in one context each contribute a data point
- Works with both standard assertions and predicate assertions