Skip to main content

Decorator

@metric

Register a metric resource that yields a Metric instance and optionally a final value. Signature:
Parameters: Returns: Decorated function registered as a metric resource Generator Requirements:
  1. Must yield a Metric instance first (this gets injected)
  2. Optionally yield a final calculated value (becomes MetricResult.value)
  3. Can assert on metric properties after all data is collected
Example:

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:
Parameters: Returns: Context manager that captures assertion results Behavior:
  • When an assertion passes inside the context, records True to all metrics
  • When an assertion fails, records False to all metrics
  • Multiple assertions in one context each contribute a data point
  • Works with both standard assertions and predicate assertions
Example:

Usage Patterns

Basic Metric Collection

Assertion-Based Collection

Multiple Metrics

Distribution Analysis

Percentile Analysis

Confidence Intervals